What if you only want some of the records?
SELECT chooses the fields. FROM chooses the table. WHERE adds a condition.
The database checks each record and only returns the ones that match that condition.
In Cambridge IGCSE Computer Science (0478 and 0984), the SQL WHERE clause filters records by testing each row against a condition, returning only matching rows in the output. Text values in conditions must be enclosed in quotation marks, while numeric values do not use quotes.
Practise filtering the Students table by Age and House so you never include non-matching records in Topic 9.4 exam questions.
SELECT chooses the fields. FROM chooses the table. WHERE adds a condition.
The database checks each record and only returns the ones that match that condition.
SELECT Name FROM Students WHERE Age = 15;
The map stays the same. Only the query becomes more precise.
| StudentID | Name | Age | House |
|---|---|---|---|
| 101 | Alice | 15 | Blue |
| 102 | Ben | 16 | Green |
| 103 | Chen | 15 | Blue |
SELECT Name FROM Students WHERE Age = 15;
SELECT Name FROM Students WHERE House = "Blue";
Choose the Name field from Students, but keep only records where House is Blue.
This ignores WHERE Age = 15.
Only matching records are returned.