Spec & Goals 3 min
AQA Spec 3.7.2 — Filtering records with WHERE; AND, OR and comparison operators
By the end of this lesson you can:
- Use
WHEREto return only records that meet a condition. - Use comparison operators (
=,>,<,>=,<=,<>). - Combine conditions with
ANDandOR.
Warm-Up 5 min
SELECT chose the columns; now WHERE chooses the rows — returning only the records that match a condition.
Quick starter
To list only students in form 10A, what test must each row pass?
Reveal the idea
The Form field must equal '10A'. In SQL: WHERE Form = '10A'. Text values go in single quotes.
Key Concept — choosing rows 14 min
SELECT fields FROM table WHERE condition;
Only records where the condition is true are returned.
Comparison operators
| Operator | Means | Example |
|---|---|---|
= | equal to | Form = '10A' |
> / < | greater / less than | Mark > 80 |
>= / <= | greater/less than or equal | Mark >= 65 |
<> | not equal to | Town <> 'Ipoh' |
Combining conditions with AND / OR
AND— both conditions must be true.OR— either condition may be true.
Reminder of the Student table:
| StudentID | Name | Form | Town | Mark |
|---|---|---|---|---|
| 101 | Aisyah | 10A | Ipoh | 78 |
| 102 | Wei Jie | 10B | Penang | 65 |
| 103 | Priya | 10A | Ipoh | 91 |
| 104 | Arjun | 11C | Johor Bahru | 54 |
| 105 | Mei Ling | 11C | Penang | 88 |
| 106 | Hafiz | 10B | Kuala Lumpur | 72 |
Worked Example — filter the students 12 min
Query 1: students who scored more than 80.
SELECT Name, Mark FROM Student WHERE Mark > 80;
| Name | Mark |
|---|---|
| Priya | 91 |
| Mei Ling | 88 |
Query 2: students in form 10A and from Ipoh.
SELECT Name FROM Student WHERE Form = '10A' AND Town = 'Ipoh';
| Name |
|---|
| Aisyah |
| Priya |
Query 3: students from Penang or Kuala Lumpur.
SELECT Name, Town FROM Student WHERE Town = 'Penang' OR Town = 'Kuala Lumpur';
| Name | Town |
|---|---|
| Wei Jie | Penang |
| Mei Ling | Penang |
| Hafiz | Kuala Lumpur |
Try It Yourself 12 min
Goal: Write a query for the names of all students in form 11C.
Goal: Write a query for students with a Mark of at least 70, showing Name and Mark.
Goal: Write a query for students in form 10B who scored below 70. State the result rows.
📝 Exam Practice 10 min
Write an SQL query to display the Name of every student whose Town is Penang.
Mark scheme
SELECT Name(1).FROM Student(1).WHERE Town = 'Penang';— correct field, quotes and value (1).
Write a query to list students in form 10A with a Mark over 75.
Mark scheme
SELECT ... FROM Student WHERE Form = '10A'(1).AND Mark > 75;(1).
State the result of SELECT Name FROM Student WHERE Mark < 60;
Mark scheme
- Arjun (only student with Mark below 60) (1).
Recap & Key Terms 3 min
WHERE filters rows by a condition. Use comparison operators (= > < >= <= <>), quoting text and dates but not numbers. Combine conditions with AND (both true) and OR (either true).
- WHERE
- The SQL clause that returns only records meeting a condition.
- Comparison operators
=,>,<,>=,<=,<>— test a field against a value.- AND
- Combines conditions so both must be true.
- OR
- Combines conditions so either may be true.
Homework 1 min
Task (≤ 15 min): Using the Student table, write queries for: (a) students not from Ipoh; (b) students in form 10A or 10B; (c) students with a mark between 70 and 90 (inclusive).
Model answer
-- (a) SELECT Name FROM Student WHERE Town <> 'Ipoh'; -- (b) SELECT Name FROM Student WHERE Form = '10A' OR Form = '10B'; -- (c) SELECT Name, Mark FROM Student WHERE Mark >= 70 AND Mark <= 90;
Award marks for: correct use of <> (1); correct OR (1); correct AND range (1).