Filter records with WHERE
Use a WHERE condition to return only the rows that match a requirement.
Exam scope and assessment notes
This sequence follows Cambridge IGCSE Computer Science 0478, 2026–2028 syllabus Version 6, Topic 9. It covers single-table databases only and the specified SELECT, FROM, WHERE, ORDER BY, SUM, COUNT, AND and OR content. The official specimen also demonstrates NOT in a filter. Multi-table joins, GROUP BY, database implementation and the separate 2029–2031 syllabus are not mapped here. Practice is original, self-checked and does not award an official Cambridge grade. Full timed papers and human subject-teacher review remain outstanding.
Before you begin
- Be able to read a small table and compare values. Each lesson introduces the database and SQL terms it uses.
Work on paper. Try each question before revealing help, and explain why your method works.
Quick readiness check
If a row fails the WHERE condition, does it appear in the result?
What you will learn
- Identify how WHERE limits records
- Write a simple equality condition
- Trace which records satisfy a filter
WHERE filters records
A WHERE condition is tested against each record. Only records for which the condition is true appear in the result.
For example, WHERE Topic = "Robotics" returns records whose Topic value equals Robotics. The field should belong to the table named in FROM.
Keep fields and records distinct
SELECT determines which columns are shown, while WHERE determines which rows are included.
If no record matches the condition, the result has no data rows. A WHERE condition does not change or delete stored records.
Pause and explain
Which clause filters for Paid = TRUE?
Worked example
WORKSHOP has four rows with Topic values Robotics, Art, Robotics and Coding. Which SessionID values match WHERE Topic = "Robotics"?
Show the worked solution
- Compare each Topic value with Robotics.
- The first and third records match.
- Return the selected field from those rows only.
Answer The SessionID values from the first and third records are returned.
Try a topic test
Choose Easy, Normal or Difficult. Save your answers and open worked review after finishing.
Test this topic →From guided practice to a new situation
Write your answer and reasoning first. Use a hint only if you are stuck. The model solution is for self-checking; your written work is not automatically marked.
Write a query to return Title for shows where Type is Jazz from PERFORMANCES.
Give me a hint
Select the output field, source table and equality filter.
Compare my reasoning
- Select Title.
- Use PERFORMANCES after FROM.
- Filter Type = "Jazz".
SELECT Title FROM PERFORMANCES WHERE Type = "Jazz";
Look for these in your work
- Selected field
- Source table
- Filter
A table contains Status values Open, Closed, Open. How many rows match WHERE Status = "Open"?
Give me a hint
Test each record's value.
Compare my reasoning
- The first row matches.
- The second does not.
- The third matches.
Two rows match.
Look for these in your work
- Each row checked
- Count correct
A query SELECT Name FROM STUDENTS WHERE YearGroup = 12 returns no rows. Give two possible explanations to check.
Give me a hint
Inspect both the data and the exact query names/values.
Compare my reasoning
- There may be no YearGroup 12 records.
- The field name or value may not match the table's stored form.
- Verify the query against the table contents.
There may be no matching records, or the field/value may be misspelled or represented differently.
Look for these in your work
- Data explanation
- Query/schema explanation
Common mistakes
- Using WHERE to name a field to display
- Filtering by a value without quotes in a text comparison
- Believing filtered-out rows were deleted
What can you explain now?
What does WHERE control?
Compare with the explanation
Which records meet the condition
WHERE filters rows, not the selected fields.
After trying it yourself, choose your next review. This is your self-assessment.
Your review choice appears on Today. Sign in to sync it across devices.
Make it stick
How does WHERE differ from SELECT?
If you needed the solution, close it and solve the problem again from a blank page. A correct answer is stronger when you can explain the reason for each step.