← IGCSE Computer Science Paper 2

Clause order in a full SQL query

The order of clauses in a full SQL query: SELECT, FROM, WHERE, then ORDER BY. WHERE filters the rows first, then ORDER BY sorts the rows that are left.

Understanding Clause order in a full SQL query in IGCSE Computer Science Paper 2

What it does: FROM names the table, then WHERE keeps only the rows that match the condition. Sorting happens later. Each clause is on its own line with capital keywords. Only the last line has a semicolon, because it ends the whole statement. A full query always runs in the order SELECT, FROM, WHERE, ORDER BY. FROM must come before WHERE.

Common mistakes: A full query starts with SELECT, which lists the fields to show. FROM comes second and names the table. Line 1 should be SELECT firstName, points. The semicolon marks the end of the whole statement, so it goes after the last clause. Line 4 should be ORDER BY price;.

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 525–538) and word search (Modules 500–538).

Take this worksheet further — free with Cloodit

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

Learning
Duo
Which clause order is correct in a full SQL query?
SELECT, WHERE, FROM, ORDER BYSELECT, FROM, WHERE, ORDER BY
Matches
SELECT firstName, points FROM students ORDER BY points WHERE points > 100;
↓
ORDER BY is placed before WHERE. The clause order must be SELECT, FROM, WHERE, ORDER BY.
Applying
Meanings
Term
SELECT FROM WHERE ORDER BY
Meaning
The order of clauses in a full SQL query: SELECT, FROM, WHERE, then ORDER BY. WHERE filters the rows first, then ORDER BY sorts the rows that are left.
Practice
SELECT firstName, points
Testing
Gaps
price;
Check Answer
Spots
1FROM firstName, points
2FROM students

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

The 'Space Rabbit' badge — Launch Pad, 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 clause order is correct in a full SQL query?
A. SELECT, WHERE, FROM, ORDER BY
B. SELECT, FROM, WHERE, ORDER BY ✓
A full query always runs in the order SELECT, FROM, WHERE, ORDER BY. FROM must come before WHERE.
2. Which statement puts ORDER BY in the right place?
A. SELECT name FROM students WHERE points > 100 ORDER BY name; ✓
B. SELECT name FROM students ORDER BY name WHERE points > 100;
WHERE must come before ORDER BY. The rows are filtered first and the remaining rows are sorted.
3. In a full query, what does the database do with WHERE and ORDER BY?
A. ORDER BY sorts all the rows, then WHERE is ignored
B. WHERE filters the rows, then ORDER BY sorts the rows that are left ✓
WHERE chooses which rows stay. ORDER BY then sorts only those remaining rows.
4. Where does the semicolon go in a statement with SELECT, FROM, WHERE and ORDER BY?
A. At the end of the ORDER BY line, once for the whole statement ✓
B. At the end of every line, after each clause
One semicolon ends the whole statement. Do not put one after each clause.
5. Which version is written in the correct style for a Cambridge IGCSE script?
A. SELECT name FROM students WHERE house = 'Red' ORDER BY name; ✓
B. select name from students order by name where house = 'Red'
Write keywords in capitals with one clause per line. The clauses must also be in the order SELECT, FROM, WHERE, ORDER BY.

Match the Pairs

SELECT firstName, points FROM students WHERE points > 100 ORDER BY points DESC; → A full query with the clauses in the correct order: SELECT, FROM, WHERE, then ORDER BY, with one semicolon at the very end.
ORDER BY points DESC; → The last clause of a full query. It sorts the rows that are left after WHERE has filtered them.
WHERE comes straight after FROM and filters the rows before they are sorted. → FROM students WHERE house = 'Red'
Keywords are written in capitals, one clause per line, and the semicolon goes only at the end of the whole statement. → SELECT name, price FROM products ORDER BY price;
SELECT firstName, points FROM students ORDER BY points WHERE points > 100; → ORDER BY is placed before WHERE. The clause order must be SELECT, FROM, WHERE, ORDER BY.
SELECT name, price; FROM products WHERE price > 5 ORDER BY price; → A semicolon is put after the SELECT line. The semicolon belongs only at the end of the whole statement.

Key Term

SELECT FROM WHERE ORDER BY
The order of clauses in a full SQL query: SELECT, FROM, WHERE, then ORDER BY. WHERE filters the rows first, then ORDER BY sorts the rows that are left.

Fill in the Blanks

1. SELECT name, price FROM products WHERE stock > 0 ORDER BY price;
Hint: Type the two-word clause that sorts the rows left after filtering. It comes last.
2. SELECT name, price FROM products WHERE stock > 0 ORDER BY price;
Hint: Type the clause that filters the rows. It must come before the sorting clause.
3. SELECT firstName FROM students WHERE yearLevel = 8 ORDER BY points DESC;
Hint: Type the keyword that makes the sort go from highest to lowest.
4. SELECT name, price FROM products WHERE stock > 0 ORDER BY price;
Hint: Type the keyword that names the table. It comes straight after the field list.
5. SELECT firstName, points FROM students WHERE points > 100 ORDER BY points;
Hint: Type the keyword that starts every query and comes before the list of fields.

Spot the Error

Question 1
A FROM firstName, points
B FROM students
C WHERE points > 100
D ORDER BY points DESC;
Line A — A full query starts with SELECT, which lists the fields to show. FROM comes second and names the table. Line 1 should be SELECT firstName, points.
Question 2
A SELECT name, price
B FROM products
C WHERE stock > 0
D ORDER BY price
Line D — The semicolon marks the end of the whole statement, so it goes after the last clause. Line 4 should be ORDER BY price;
Question 3
A SELECT firstName
B FROM students;
C WHERE house = 'Red'
D ORDER BY firstName;
Line B — A semicolon ends the whole statement. Putting one after FROM ends the query too early, before WHERE and ORDER BY. Line 2 should be FROM students with no semicolon.
Question 4
A SELECT studentId, mark
B FROM results
C AND mark >= 50
D ORDER BY mark DESC;
Line C — A condition needs the WHERE keyword to start the filter. AND can only join extra conditions to an existing WHERE. Line 3 should be WHERE mark >= 50.
Question 5
A SELECT name, stock;
B FROM products
C WHERE stock < 10
D ORDER BY stock;
Line A — The semicolon belongs only at the end of the whole statement. Ending the SELECT line with one stops the query before FROM. Line 1 should be SELECT name, stock.

Student with a class code? Join your class →