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.
Two functions calculate a single value from a whole column of results rather than listing the rows.
SUM(field)adds up all the values in a numeric field across the records the query selects.
SELECT SUM(DailyFeedKg)
FROM tbl_zoo
WHERE InCaptivity = 'Yes';
This adds the daily feed for every captive species (35 + 3 + 2 + 1 + 25 + 2 + 20 + 4 = 92), so the query returns a single value: 92.
COUNT(field)returns how many records the query selects, rather than the records themselves.
SELECT COUNT(Species)
FROM tbl_zoo
WHERE InCaptivity = 'No';
Two species are not in captivity (Anaconda and Tarantula), so this returns 2. Using COUNT(*) counts every selected record in the same way.
Choosing between SUM, COUNT and ORDER BY
What comes up: a query asks for a total, a number of records, or a sorted list from a single table (often worth 2-3 marks, one per correct clause).
Write: use SUM(field) when the question asks for a total of a numeric column; use COUNT(field) (or COUNT(*)) when it asks how many records match; add ORDER BY field ASC or ORDER BY field DESC when it asks for the results in order.
Watch out: SUM adds the values, while only counts how many rows there are — using where the question wants a total (or the other way round) loses the mark. State or explicitly so the sort direction is unambiguous.
COUNTCOUNTASCDESC