Writing an SQL query from a requirement
Turn a request into one SQL statement: pick fields after SELECT, the table after FROM, conditions in WHERE, sort with ORDER BY, and use SUM or COUNT for totals and how many.
Understanding Writing an SQL query from a requirement in IGCSE Computer Science Paper 2
What it does: The request asks for a total, so SUM wraps the quantity field, and WHERE limits it to product 2. ORDER BY comes last and DESC puts the highest price first. The names go after SELECT, the table after FROM, and the condition house = 'Red' goes in WHERE. "How many records" means COUNT. SUM adds up the values, so it gives the total price instead. The student must meet both conditions at the same time, so use AND. OR would include students who meet only one. Dates are stored as text, so the date value must be inside quotes. Without quotes SQL treats it as a sum.
Common mistakes: The table is called students, so the FROM line must read FROM students. A table name that does not exist makes the query fail. The keyword is misspelt. The table name must follow FROM, so the line should be FROM products.
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
SELECT fields FROM table WHERE condition ORDER BY field DESC;Fill in the Blanks
Spot the Error
Student with a class code? Join your class →