1. What is this?
A condition is a test that is true or false per row, e.g. age > 30. WHERE keeps only rows passing the test: SELECT name FROM users WHERE age > 30. Text comparisons use single quotes: WHERE name = 'Ava'. A variable here is the column value, changing row by row.
2. Why do we use it?
Nobody reads a million rows. Filters find adults, recent orders, or one account.
3. Syntax breakdown
SELECT name FROM users WHERE age > 30;
Keeps rows where age exceeds 30. > means greater than.
WHERE name = 'Ava'
= tests equality. Text needs single quotes.
WHERE age >= 18 AND age < 65
AND combines tests; both must hold.
5. Common mistakes
- Double quotes for text in some engines — use single quotes for values.
- Using = with NULL (use IS NULL instead) — covered in intermediate.
- Forgetting that WHERE runs before display — you cannot use a display alias there in some engines.
Practice task
List names of users younger than 30.
Hint
SELECT name FROM users WHERE age < 30;
Try it below — tests run automatically when you press Run.
Output
Press Run to see output.
Mini quiz
3 questions. Answer, then check.
1. What does WHERE do?
2. How is text written in SQL?
3. What does AND do?