0984

Database Concepts

Databases · 5 question types

Exam Frequency Analysis

Past paper frequency (2018 to 2024)

This topic accounts for approximately 4% of your exam marks.

stable
Rare
Stable4%

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:

ClauseWhat it does
SELECTLists which fields (columns) to display in the result
FROMNames the table to read from
WHEREFilters which records (rows) to include

The semicolon at the end is the SQL "end of statement" marker.

SELECT every field

To return every column for every record, use the wildcard * after SELECT:

SELECT *
FROM Customers;

This returns the whole table.

SELECT specific fields

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.

SELECT with a WHERE filter

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.

Exam tip

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.

A customers table to practise on

Consider this Customers table:

IDNameAgeCityCountry
101Maya Hassan32TorontoCanada
102Liam O'Brien25DublinIreland
103Hiroshi Tanaka47OsakaJapan
104Priya Gupta19MumbaiIndia

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;

IDNameAge
101Maya Hassan32
103Hiroshi Tanaka47

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