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 the 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 |
A keeper wants the names of every species that is held in captivity and eats more than 10 kg of food a day:
SELECT Species
FROM tbl_zoo
WHERE InCaptivity = 'Yes'
AND DailyFeedKg > 10;
Working through each record against both conditions:
Result:
| Species |
|---|
| Giraffe |
| Bison |
| Gorilla |
| 5 |
| Macaw | Yes | 1 |
| Bison | Yes | 25 |
| Pelican | Yes | 2 |
| Tarantula | No | 1 |
| Gorilla | Yes | 20 |
| Komodo Dragon | Yes | 4 |