← Years 7–8 Data & Information

Sorting query results

Sorts query results by the Score field from highest to lowest. Use ASC for lowest to highest. Add a second field after a comma to sort ties, like ORDER BY Score DESC, Name.

Understanding Sorting query results in Years 7–8 Data & Information

What it does: Sorting the Score field in descending order puts the best scores at the top of the results. The second field after the comma is only used to sort rows that have the same value in the first field. DESC means descending, so the biggest values come first. ASC puts the smallest first. ASC means ascending, so results go from lowest to highest. Ascending order for text is alphabetical, from A to Z. The field name comes first, then the direction: ORDER BY Points DESC.

Common mistakes: The word BY is missing. Sorting needs ORDER BY, so the line should be ORDER BY Score DESC;. DOWN is not a sort direction. Use DESC for highest to lowest, so the line should be ORDER BY Score DESC.

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 47–80) and word search (Modules 9–80).

Take this worksheet further — free with Cloodit

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

Learning
Duo
Which query shows the highest scores first?
SELECT * FROM Results ORDER BY Score DESCSELECT * FROM Results ORDER BY Score ASC
Matches
ORDER Score DESC
↓
The word BY is missing. It should be ORDER BY Score DESC.
Applying
Meanings
Term
ORDER BY Score DESC
Meaning
Sorts query results by the Score field from highest to lowest. Use ASC for lowest to highest. Add a second field after a comma to sort ties, like ORDER BY Score DESC, Name.
Practice
SELECT Name, Score
Testing
Gaps
Score DESC
Check Answer
Spots
2FROM Results
3ORDER Score DESC;

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

The 'Walrus' badge — Method Master, 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 shows the highest scores first?
A. SELECT * FROM Results ORDER BY Score ASC
B. SELECT * FROM Results ORDER BY Score DESC ✓
DESC means descending, so the biggest values come first. ASC puts the smallest first.
2. True or false: ORDER BY Score ASC puts the lowest score at the top.
A. False
B. True ✓
ASC means ascending, so results go from lowest to highest.
3. Which clause sorts the results of a query?
A. ORDER BY ✓
B. SORT WHEN
ORDER BY is the SQL clause that sorts query results by a field.
4. What does ORDER BY Name ASC do to a list of student names?
A. Sorts them A to Z ✓
B. Sorts them Z to A
Ascending order for text is alphabetical, from A to Z.
5. Two students both scored 90. Which query sorts the tied students by Name?
A. ORDER BY Score DESC, Name ✓
B. ORDER BY Score DESC AND Name
Put a comma between the fields. The second field is used to sort ties in the first.

Match the Pairs

ORDER BY Score DESC → Sorts the results from the highest score to the lowest score
ORDER BY Score ASC → Sorts the results from the lowest score to the highest score
Show the top scores first → SELECT Name, Score FROM Results ORDER BY Score DESC
Sort by Score, then sort tied students by Name → ORDER BY Score DESC, Name
ORDER Score DESC → The word BY is missing. It should be ORDER BY Score DESC.
ORDER BY Score DESC Name → There is no comma between the two sort fields. It should be ORDER BY Score DESC, Name.

Key Term

ORDER BY Score DESC
Sorts query results by the Score field from highest to lowest. Use ASC for lowest to highest. Add a second field after a comma to sort ties, like ORDER BY Score DESC, Name.

Fill in the Blanks

1. SELECT Name, Score FROM Results ORDER BY Score DESC
Hint: Type the two-word keyword that sorts query results
2. SELECT Name, Score FROM Results ORDER BY Score DESC
Hint: Type the keyword that puts the highest scores first
3. SELECT Name, Time FROM Races ORDER BY Time ASC
Hint: Type the keyword that sorts from lowest to highest
4. SELECT Name, Score FROM Results ORDER BY Score DESC, Name
Hint: Type the second field that sorts students with tied scores
5. SELECT Name, Score FROM Results ORDER BY Score DESC
Hint: Type the field the results are sorted by to show the top scores

Spot the Error

Question 1
A SELECT Name, Score
B FROM Results
C ORDER Score DESC;
Line C — The word BY is missing. Sorting needs ORDER BY, so the line should be ORDER BY Score DESC;
Question 2
A SELECT * FROM Results
B ORDER BY Score DOWN
C LIMIT 3;
Line B — DOWN is not a sort direction. Use DESC for highest to lowest, so the line should be ORDER BY Score DESC.
Question 3
A SELECT Name, Score
B FROM Results
C ORDER BY Score DESC Name;
Line C — Two sort fields must be separated by a comma. It should be ORDER BY Score DESC, Name; so ties are sorted by Name.
Question 4
A -- Top scores first
B SELECT Name, Score
C FROM Results
D ORDER BY Score ASC;
Line D — ASC sorts lowest to highest, so the top scores would be last. Use DESC to put the top scores first.
Question 5
A SELECT Name, Score
B FROM Results;
C WHERE Score > 50
D ORDER BY Score DESC;
Line B — The semicolon ends the query too early, so the WHERE and ORDER BY lines would be cut off. Remove it: FROM Results

Student with a class code? Join your class →