Every retrieval query answers three questions in a fixed order.
| Clause | Question it answers |
|---|
| SELECT | Which fields (columns) do I want to see? |
| FROM | Which table is the data in? |
| WHERE | Which records (rows) do I want? |
The tables used throughout this section
Student
| StudentID | Forename | Surname | YearGroup | TutorID | FeesPaid |
|---|
| S1041 | Amara | Okafor | 10 | T07 | True |
| S1042 | Ben | Whitton | 11 | T11 | False |
| S1043 | Chen | Liu | 10 | T07 | True |
| S1044 | Dina | Petrov | 11 | T07 | False |
Tutor
| TutorID | TutorName | Room |
|---|
| T07 | Ms Rahman | 12 |
| T11 | Mr Ellis | 5 |
Selecting fields
SELECT Forename, Surname
FROM Student
Returns just those two columns, for every record — because there is no WHERE clause.
To return all fields, use *:
SELECT *
FROM Student
Filtering records with WHERE
SELECT Forename, Surname
FROM Student
WHERE YearGroup = 10
Returns Amara Okafor and Chen Liu.
⚠️ Quotes. Text values are enclosed in quotation marks; numbers are not.
SELECT StudentID
FROM Student
WHERE Surname = 'Liu' -- text: quotes needed
SELECT StudentID
FROM Student
WHERE YearGroup = 11 -- number: no quotes
Comparison operators
| Operator | Meaning | Example |
|---|
= | Equal to | WHERE YearGroup = 10 |
<> | Not equal to | WHERE YearGroup <> 10 |
> | Greater than | WHERE Price > 20 |
< | Less than | WHERE Price < 20 |
>= | Greater than or equal to | WHERE YearGroup >= 10 |
<= | Less than or equal to | WHERE Price <= 50 |
Combining conditions
SELECT Forename, Surname
FROM Student
WHERE YearGroup = 11 AND FeesPaid = False
| Logical operator | Effect |
|---|
| AND | Both conditions must be true |
| OR | At least one condition must be true |
| NOT | Reverses the condition |
⚠️ AND narrows, OR widens. WHERE YearGroup = 10 AND YearGroup = 11 returns nothing, because no record can be in both years. If you want students in either year, you need OR.
Partial matches with LIKE
SELECT Forename, Surname
FROM Student
WHERE Surname LIKE 'W%'
Finds surnames starting with W. The % wildcard stands for any sequence of characters, so '%son' finds those ending in "son" and '%an%' those containing "an".
AQA tip. Answer questions in the order SELECT → FROM → WHERE. It is also worth reading the question to check whether it asks which fields to show or which records to find — those are different clauses, and answering the wrong one is a common way to lose an otherwise correct query.