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.
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.)