← VCE Spreadsheets, SQL & Visualisation

SQL ORDER BY

Sorts the rows a SELECT query returns by a chosen field. It sorts A to Z or lowest to highest by default (ASC), or the reverse if you add DESC after the field name.

Understanding SQL ORDER BY in VCE Spreadsheets, SQL & Visualisation

What it does: ASC means ascending, so the lowest price comes first. It is the default, but writing it makes the order clear. WHERE filters the rows first, then ORDER BY sorts what is left. DESC puts the largest age (the oldest) first. Text sorts A to Z by default. Add DESC to get Z to A. DESC goes after the field name, at the end of the ORDER BY part.

Common mistakes: DESC must come after the field name, not before it. It should be ORDER BY score DESC; so the highest scores come first. The keyword is ORDER BY, not just ORDER. The line should be ORDER BY name ASC; to sort the names from A to Z.

Class: _____________________  ·  Name: _____________________  ·  Date: _________

Free printable worksheet with full answer key — or add this module to a class and your students practise it interactively.

This module's key terms are also in a printable crossword (Modules 45–54) and word search (Modules 35–54).

Take this worksheet further — free with Cloodit

Each concept is reinforced from every angle — learned, then applied, then tested.

Learning
Duo
Which query lists students from the youngest age to the oldest age?
SELECT * FROM students ORDER BY age ASC;SELECT * FROM students ORDER BY age DESC;
Matches
SELECT * FROM Students ORDER BY WHERE year = 10;
↓
WHERE must come before ORDER BY, and ORDER BY needs a field name. Fix: WHERE year = 10 ORDER BY name;
Applying
Meanings
Term
ORDER BY
Meaning
Sorts the rows a SELECT query returns by a chosen field. It sorts A to Z or lowest to highest by default (ASC), or the reverse if you add DESC after the field name.
Practice
SELECT name, score
Testing
Gaps
score;
Check Answer
Spots
3WHERE year = 10
4ORDER BY DESC score;

Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.

The 'Blue-Ringed Octopus' badge — Reef Legend, one of Cloodit's 106 collectible badges
Students earn collectable badges

Over 100 of them, across seven natural biomes.

Study Buddy
Students build a real study resource

Turns their work into revision material ready for Flash Cards and Exam study.

Diamond Dash — one of Cloodit's live, competitive Sprint games
Students lock in with Sprints

Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.

A Cloodit certificate of achievement, ready to personalise and print
Custom printable certificates

Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.

Quick Questions

1. Which query lists students from the youngest age to the oldest age?
A. SELECT * FROM students ORDER BY age ASC; ✓
B. SELECT * FROM students ORDER BY age DESC;
ASC sorts lowest to highest, so the youngest (smallest age) comes first. DESC would put the oldest first.
2. True or false: if you write ORDER BY score with no ASC or DESC, the rows are sorted from highest to lowest.
A. False ✓
B. True
The default is ASC, so ORDER BY score sorts from lowest to highest.
3. Which query shows the top scores first in a games table?
A. SELECT * FROM games ORDER BY score DESC; ✓
B. SELECT * FROM games ORDER BY score;
DESC reverses the order so the highest score appears first. Without it the lowest score comes first.
4. A table is sorted with ORDER BY name. Which order do the names appear in?
A. Zara, Chen, Bella, Alex
B. Alex, Bella, Chen, Zara ✓
Text sorts A to Z by default. Add DESC to get Z to A.
5. Which query has the correct syntax for sorting the results of a filtered search?
A. SELECT * FROM pets ORDER BY name WHERE age > 2;
B. SELECT * FROM pets WHERE age > 2 ORDER BY name; ✓
WHERE filters the rows first, so it comes before ORDER BY. ORDER BY is usually the last part of the query.

Match the Pairs

SELECT name, score FROM Students ORDER BY score DESC; → Lists students from the highest score to the lowest score
SELECT name FROM Students ORDER BY name; → Lists student names from A to Z
Sort the results by price from the lowest to the highest, using ASC to say so clearly → SELECT * FROM Games ORDER BY price ASC;
Show only Year 10 students, then sort those rows by age from oldest to youngest → SELECT * FROM Students WHERE year = 10 ORDER BY age DESC;
SELECT * FROM Students ORDER BY WHERE year = 10; → WHERE must come before ORDER BY, and ORDER BY needs a field name. Fix: WHERE year = 10 ORDER BY name;
SELECT name FROM Students ORDER BY DESC score; → DESC goes after the field name, not before it. Fix: ORDER BY score DESC;

Key Term

ORDER BY
Sorts the rows a SELECT query returns by a chosen field. It sorts A to Z or lowest to highest by default (ASC), or the reverse if you add DESC after the field name.

Fill in the Blanks

1. SELECT name, score FROM students ORDER BY score;
Hint: Type the two-word clause that sorts the rows a query returns.
2. SELECT name, score FROM students ORDER BY score DESC;
Hint: Type the keyword that sorts from highest to lowest.
3. SELECT name FROM students ORDER BY name;
Hint: Type the text field being listed so the rows go from A to Z.
4. SELECT name, score FROM students WHERE year = 10 ORDER BY score DESC;
Hint: Type the clause that filters the rows before they are sorted.
5. SELECT name, score FROM students WHERE year = 9 ORDER BY score ASC;
Hint: Type the keyword for sorting lowest to highest, which is the default direction.

Spot the Error

Question 1
A SELECT name, score
B FROM students
C WHERE year = 10
D ORDER BY DESC score;
Line D — DESC must come after the field name, not before it. It should be ORDER BY score DESC; so the highest scores come first.
Question 2
A SELECT name FROM pets
B ORDER name ASC;
C SELECT name FROM pets
D ORDER BY name DESC;
Line B — The keyword is ORDER BY, not just ORDER. The line should be ORDER BY name ASC; to sort the names from A to Z.
Question 3
A SELECT title, price FROM books
B WHERE price < 20;
C ORDER BY price DESC;
Line B — The semicolon ends the query too early, so the ORDER BY line is cut off from it. Remove the semicolon so it reads WHERE price < 20 and the semicolon goes at the end of the ORDER BY line.
Question 4
A SELECT name, points
B FROM teams
C ORDER BY points DOWN;
Line C — SQL does not have a DOWN keyword. To sort from highest to lowest, use DESC: ORDER BY points DESC;
Question 5
A SELECT name, city
B FROM customers
C WHERE city = 'Perth'
D SORT BY name;
Line D — SQL uses ORDER BY to sort results, not SORT BY. It should be ORDER BY name; which sorts the names from A to Z.

Student with a class code? Join your class →