Databases · 5 question types
Past paper frequency (2018 to 2024)
This topic accounts for approximately 4% of your exam marks.
SQL SELECT queries and database structure (tables, fields, records) appear as 4 to 6 mark questions.
A typical SQL query has up to three clauses:
SELECT field1, field2, ...
FROM TableName
WHERE condition;
Each line has a specific job:
| Clause | What it does |
|---|---|
| SELECT | Lists which fields (columns) to display in the result |
| FROM | Names the table to read from |
| WHERE | Filters which records (rows) to include |
The semicolon at the end is the SQL "end of statement" marker.
To return every column for every record, use the wildcard * after SELECT:
SELECT *
FROM Customers;
This returns the whole table.
To return only certain columns, list them by name:
SELECT FirstName, LastName, Age
FROM Customers;
Only those three columns appear in the result, even if the table has many more.
To return only certain rows, add a WHERE clause with a condition:
SELECT *
FROM Customers
WHERE Age > 25;
Only customers older than 25 are returned.
Writing a SELECT query
What comes up: write a SQL query to retrieve specific fields from a table under a given condition (typically 3 marks, one per clause).
Write (three marks): (1) SELECT followed by the field names to display — or * to display every field; (2) FROM followed by the table name; (3) WHERE followed by the filter condition, with any text value in single quotes (e.g. WHERE City = 'Lagos').
Watch out: two common slip-ups cost marks independently. First, omitting quotes around text values — writing WHERE City = Lagos instead of WHERE City = 'Lagos' makes the database look for a column called Lagos, breaking the query. Second, using when specific fields were asked for (or listing specific fields when the question says "all details") — read the question carefully to match what SELECT should list.
Consider this Customers table:
| ID | Name | Age | City | Country |
|---|---|---|---|---|
| 101 | Maya Hassan | 32 | Toronto | Canada |
| 102 |
*| Liam O'Brien |
| 25 |
| Dublin |
| Ireland |
| 103 | Hiroshi Tanaka | 47 | Osaka | Japan |
| 104 | Priya Gupta | 19 | Mumbai | India |
Query 1: SELECT * FROM Customers; returns all five fields for all four records (the whole table).
Query 2: SELECT ID, Name, Age FROM Customers WHERE Age > 25;
| ID | Name | Age |
|---|---|---|
| 101 | Maya Hassan | 32 |
| 103 | Hiroshi Tanaka | 47 |
(Liam O'Brien is excluded because his age is exactly 25, while the query asked for strictly greater than 25. Priya Gupta is excluded because 19 < 25.)