Working out the output of an SQL statement
To find a query's output, first keep the rows that pass WHERE, then sort them with ORDER BY, then show only the SELECT fields or the SUM or COUNT result.
Understanding Working out the output of an SQL statement in IGCSE Computer Science Paper 2
What it does: No student has more than 500 points, so no row passes WHERE and the output table is empty. Each row only needs to pass one of the two tests, so WHERE keeps it. SELECT then shows only firstName. WHERE removes every row that fails the condition, so only the 2 rows with Year = 10 are shown. DESC means descending order, so the largest value comes first. AND needs both conditions to be true. OR is the one that needs just one. OR keeps a row if at least one condition is true. A single House value cannot be both Red and Blue.
Common mistakes: Text values must be in quotes. Without them Red is read as a field name, so no rows can be kept. It should be WHERE house = 'Red'. SQL tests equality with a single =. The double == is not valid, so the WHERE step fails. It should be WHERE stock = 0.
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.
Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.
Over 100 of them, across seven natural biomes.
Turns their work into revision material ready for Flash Cards and Exam study.
Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.
Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.
Quick Questions
Match the Pairs
Key Term
WHERE, ORDER BY, SELECTFill in the Blanks
Spot the Error
Student with a class code? Join your class →