Sort query results in ascending order
Use ORDER BY ASCENDING to arrange the returned records by a field value.
Section 9 · Databases
Exam scope and assessment notes
This sequence follows Cambridge IGCSE Computer Science 0478, 2026–2028 syllabus Version 6, Topic 9. It covers single-table databases only and the specified SELECT, FROM, WHERE, ORDER BY, SUM, COUNT, AND and OR content. The official specimen also demonstrates NOT in a filter. Multi-table joins, GROUP BY, database implementation and the separate 2029–2031 syllabus are not mapped here. Practice is original, self-checked and does not award an official Cambridge grade. Full timed papers and human subject-teacher review remain outstanding.
Before you begin
- Be able to read a small table and compare values. Each lesson introduces the database and SQL terms it uses.
Work on paper. Try each question before revealing help, and explain why your method works.
Quick readiness check
Does sorting remove records?
What you will learn
- Place ORDER BY after the source and filter clauses
- Sort by a selected field
- Explain that sorting changes order, not the stored records
ORDER BY controls result order
Add ORDER BY followed by a field name and ASCENDING to list results from lower to higher values or alphabetically A to Z.
Place ORDER BY after FROM and any WHERE condition. The syllabus uses the full keyword ASCENDING.
Sorting is not filtering
ORDER BY rearranges the result rows; it does not add or remove records.
When two values are equal, the syllabus does not promise a particular relative order unless another sort field is supplied. Do not infer extra behavior from an example table.
Pause and explain
Which keyword requests alphabetical A-to-Z order?
Worked example
Return SessionID and Topic from WORKSHOP, alphabetically by Topic.
Show the worked solution
- Select the two fields to display.
- Name WORKSHOP after FROM.
- Sort by Topic in ascending order.
Answer SELECT SessionID, Topic FROM WORKSHOP ORDER BY Topic ASCENDING;
Try a topic test
Choose Easy, Normal or Difficult. Save your answers and open worked review after finishing.
Test this topic →From guided practice to a new situation
Write your answer and reasoning first. Use a hint only if you are stuck. The model solution is for self-checking; your written work is not automatically marked.
Write a query to display Name and YearGroup from STUDENTS in ascending YearGroup order.
Give me a hint
Use the sort field after ORDER BY.
Compare my reasoning
- Select Name and YearGroup.
- Use STUDENTS after FROM.
- Append ORDER BY YearGroup ASCENDING.
SELECT Name, YearGroup FROM STUDENTS ORDER BY YearGroup ASCENDING;
Look for these in your work
- Fields
- Table
- Ascending clause
A result originally shows scores 8, 3 and 6. What order is requested by ORDER BY Score ASCENDING?
Give me a hint
Arrange from smallest to largest.
Compare my reasoning
- Compare 3, 6 and 8.
- List the lowest first.
- Keep all three rows.
3, 6, 8; no row is removed.
Look for these in your work
- Order correct
- Rows retained
A user asks for the oldest event first and the table has a Date field. Which sort direction is appropriate if earlier dates are smaller? Explain.
Give me a hint
Ascending puts earlier values before later values.
Compare my reasoning
- Use Date as the sort field.
- Choose ascending order.
- Retain each matching event; only their order changes.
ORDER BY Date ASCENDING, because earlier dates should appear first.
Look for these in your work
- Field chosen
- Direction justified
Common mistakes
- Putting ORDER BY before WHERE
- Sorting by an incorrect field
- Thinking a sort changes the data stored in the table
What can you explain now?
What does ORDER BY ASCENDING do?
Compare with the explanation
Orders results from lower to higher or A to Z
It determines the presentation order of result rows.
After trying it yourself, choose your next review. This is your self-assessment.
Your review choice appears on Today. Sign in to sync it across devices.
Make it stick
Where does ORDER BY appear in a query with WHERE?
If you needed the solution, close it and solve the problem again from a blank page. A correct answer is stronger when you can explain the reason for each step.