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 common exam question gives a table and a SELECT query and asks which records the query returns. The approach:
Using the Customers table from section 6:
SELECT *
FROM Customers
WHERE City = 'Dublin' OR City = 'Osaka';
Step by step:
City = 'Toronto' → does not match either → excluded.City = 'Dublin' → matches → included.City = 'Osaka' → matches → included.City = 'Mumbai' → does not match either → excluded.Result:
| ID | Name | Age | City | Country |
|---|---|---|---|---|
| 102 | Liam O'Brien | 25 | Dublin | Ireland |
| 103 | Hiroshi Tanaka | 47 | Osaka | Japan |
Consider the tbl_zoo table:
| Species | InCaptivity | DailyFeedKg |
|---|---|---|
| Giraffe | Yes | 35 |
| Cheetah | Yes | 3 |
| Tortoise | Yes | 2 |
| Anaconda | No | 5 |
| Macaw | Yes | 1 |
| Bison | Yes | 25 |
| Pelican | Yes | 2 |
| Tarantula | No | 1 |
| Gorilla | Yes | 20 |
| Komodo Dragon | Yes | 4 |
Example — Write a SQL query that returns the names of every species that is currently in captivity AND requires more than 10 kg of feed per day.
SELECT Species
FROM tbl_zoo
WHERE InCaptivity = 'Yes' AND DailyFeedKg > 10;
Result:
| Species |
|---|
| Giraffe |
| Bison |
| Gorilla |
(Cheetah, Tortoise, Macaw, Pelican and Komodo Dragon are excluded because their feed requirement is at or below 10 kg. Anaconda and Tarantula are excluded because InCaptivity = 'No'.)