AQA · GCSE · Computer Science
Course version: 8525 · Version from Sept 2020
Structured query language (SQL): ORDER BY…ASC | DESC
ORDER BY sorts the rows a query returns.
Checked against the AQA 8525 specification (opens in a new tab) on .
- Point 5 of 10
Study notes
From the checked teaching notes for this specification point.
The idea
ORDER BY sorts the rows a query returns. It comes after SELECT, FROM and any WHERE clause, and names the column to sort on. ASC sorts ascending, from smallest to largest or A to Z; DESC sorts descending, from largest to smallest or Z to A. Without a direction the database usually defaults to ascending, but stating ASC or DESC makes the intended order explicit. Sorting changes only the order of rows, not which rows are returned, so a WHERE filter still decides membership. For example, SELECT Name, Score FROM Results WHERE Score > 50 ORDER BY Score DESC lists qualifying pupils from highest score down. Practise predicting the first and last rows a given ORDER BY produces.
What earns the marks
- ORDER BY sorts the rows returned by a query according to a named column.
- ASC orders ascending (smallest to largest, A to Z); DESC orders descending (largest to smallest, Z to A).
- ORDER BY is placed after SELECT, FROM and any WHERE clause.
- Sorting changes row order only; the WHERE clause still determines which rows appear.
- Naming the direction explicitly avoids relying on a default order.
Common mistakes and how to put them right
Believing ORDER BY removes rows.
Put it right: It only reorders the rows already selected, while WHERE controls which rows appear.
Swapping the meanings of ASC and DESC.
Put it right: ASC goes up (A to Z, low to high) and DESC goes down (Z to A, high to low).
Placing ORDER BY before WHERE.
Put it right: Put the WHERE filter first and the ORDER BY clause last.
Exam tips
- State the first and last row a query would output to prove you understand the chosen direction.
- Check whether the question asks about row order or row membership, and answer accordingly.
- Write the clause order SELECT, FROM, WHERE, ORDER BY when constructing or checking a statement.
Try the lesson
The start of the Structured query language (SQL): ORDER BY…ASC | DESC lesson, made from checked teaching notes for this specification point.
Have a go first
A query ends with the clause ORDER BY Surname DESC. In which order will the records be returned?
There is more to this lesson
The full lesson goes on to check your understanding and help you earn the marks. Create a free account to carry on, with your progress saved.
A week of Premium from your first lesson · Then the free plan continues · No card, no charge
Test your understanding of Structured query language (SQL): ORDER BY…ASC | DESC
Active recall beats re-reading. Take an instant quiz now to test what you’ve learned and lock it into long-term memory.
A week of Premium from your first lesson · Then the free plan continues · No card, no charge