← IGCSE Computer Science Paper 2

Completing an SQL script

Completing an SQL script: read the task, then fill the gap with the right field, WHERE condition, ASC or DESC, AND or OR, or SUM or COUNT so the query returns exactly what is asked.

Understanding Completing an SQL script in IGCSE Computer Science Paper 2

What it does: SUM adds up the values in a numeric field, while COUNT would only give how many records there are. OR returns a record if either condition is true. AND would only return products that meet both conditions. DESC sorts from highest to lowest. ASC sorts from lowest to highest, which is the opposite of what the task asks for. The field list after SELECT gives the columns, WHERE filters to Red house and DESC puts the biggest points value first. A WHERE clause with no condition is incomplete, so the missing condition must be filled in to match the task.

Common mistakes: The task asks for first name and points, but the query selects house. The missing field after SELECT should be points: SELECT firstName, points. Highest first means descending order. The sort direction must be DESC, not ASC.

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
Task: show only the Name of every student. Which completes SELECT ___ FROM Student; ?
Name* WHERE Name
Matches
SELECT name, price FROM products ORDER BY price; -- task: most expensive first
↓
The sort direction is missing. ORDER BY defaults to ASC, so the cheapest comes first. DESC must be added after price.
Applying
Meanings
Term
SELECT field FROM table WHERE condition;
Meaning
Completing an SQL script: read the task, then fill the gap with the right field, WHERE condition, ASC or DESC, AND or OR, or SUM or COUNT so the query returns exactly what is asked.
Practice
SELECT firstName, points
Testing
Gaps
SELECT
Check Answer
Spots
1-- Show first name and points
2SELECT firstName, house

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

The 'Squirrel' badge — Module Hoarder, 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. Task: show only the Name of every student. Which completes SELECT ___ FROM Student; ?
A. * WHERE Name
B. Name ✓
The gap after SELECT holds the field you want in the output. Name returns just that one field; adding WHERE here would break the statement.
2. Task: list students in Year 10 only. Which completes SELECT Name FROM Student ___ ; ?
A. WHERE Year = 10 ✓
B. ORDER BY Year = 10
A condition that filters records goes after WHERE. ORDER BY only sorts records, it does not choose them.
3. Task: show the products with the highest Price first. Which completes SELECT Name FROM Product ORDER BY Price ___ ; ?
A. DESC ✓
B. ASC
DESC sorts from highest to lowest. ASC sorts from lowest to highest, which is the opposite of what the task asks for.
4. Task: show students in Year 9 who are also in House 'Red'. Which completes WHERE Year = 9 ___ House = 'Red'; ?
A. AND ✓
B. OR
AND means both conditions must be true. OR would also return Year 9 students from other houses and Red students from other years.
5. Task: show students who are in House 'Red' or House 'Blue'. Which completes WHERE House = 'Red' ___ House = 'Blue'; ?
A. AND
B. OR ✓
No student can be in two houses at once, so AND would return nothing. OR returns students who match either house.

Match the Pairs

SELECT firstName, points FROM students WHERE house = 'Red' ORDER BY points DESC; → Shows the first name and points of Red house students, with the highest points first
SELECT COUNT(studentId) FROM students WHERE yearLevel = 8 AND house = 'Blue'; → Counts the students who are in Year 8 and also in Blue house
The task asks for the total of all the points in the table, so the missing function in the gap is SUM → SELECT SUM(points) FROM students;
The task asks for products costing more than 5 OR with no stock, so the missing keyword in the gap is OR → SELECT name FROM products WHERE price > 5 OR stock = 0;
SELECT name, price FROM products ORDER BY price; -- task: most expensive first → The sort direction is missing. ORDER BY defaults to ASC, so the cheapest comes first. DESC must be added after price.
SELECT firstName FROM students WHERE; -- task: students with more than 100 points → The condition after WHERE is missing. It needs a field, an operator and a value, such as points > 100.

Key Term

SELECT field FROM table WHERE condition;
Completing an SQL script: read the task, then fill the gap with the right field, WHERE condition, ASC or DESC, AND or OR, or SUM or COUNT so the query returns exactly what is asked.

Fill in the Blanks

1. SELECT lastName FROM students;
Hint: Type the field name that outputs each student's family name.
2. SELECT firstName FROM students WHERE points > 100;
Hint: Type the condition that keeps only students with more than one hundred points.
3. SELECT firstName, points FROM students ORDER BY points DESC;
Hint: Type the sort direction keyword that lists the highest points first.
4. SELECT firstName FROM students WHERE yearLevel = 7 AND points > 100;
Hint: Type the logical operator needed when a student must meet both conditions.
5. SELECT SUM(points) FROM students WHERE house = 'Red';
Hint: Type the function that adds up the values in the field, rather than counting records.

Spot the Error

Question 1
A -- Show first name and points
B SELECT firstName, house
C FROM students
D WHERE house = 'Red';
Line B — The task asks for first name and points, but the query selects house. The missing field after SELECT should be points: SELECT firstName, points
Question 2
A -- Highest points first
B SELECT firstName, points
C FROM students
D ORDER BY points ASC;
Line D — Highest first means descending order. The sort direction must be DESC, not ASC.
Question 3
A -- How many students are Red?
B SELECT SUM(studentId)
C FROM students
D WHERE house = 'Red';
Line B — The task asks how many, so the query must count records. It should use COUNT, not SUM. Adding up ID numbers gives a meaningless total.
Question 4
A -- Products with stock under 10
B SELECT name, stock
C FROM products
D WHERE stock > 10;
Line D — Stock under 10 needs the less-than operator. The condition should be WHERE stock < 10; using > returns the wrong records.
Question 5
A SELECT firstName, price
B FROM students
C WHERE house = 'Blue'
D ORDER BY points DESC;
Line A — The students table has no price field. The missing field after SELECT should be a real field from students, such as points, which is also used in ORDER BY.

Student with a class code? Join your class →