Lesson 11 of 30
37%
WHERE
WHERE filters rows. Only matching rows come back.
Think of a sieve. The table is the mix. WHERE is the holes you keep.
Equals
Use a single equals sign. SQL is not JavaScript.
sql
Result
| name | city |
|---|---|
| Ada | London |
1 row
Compare numbers
1
> greater than
2
< less than
3
>= at least
4
<= at most
5
<> or != not equal
sql
Result
| name | age |
|---|---|
| Ada | 12 |
| Lin | 13 |
| Omar | 12 |
3 rows
Text vs numbers
Quotes mean text. No quotes mean a number.
WHERE age = '12' can still work, but WHERE age = 12 is the honest version.
Filter then show
SELECT chooses columns. WHERE chooses rows. They work together.
sql
Result
| name |
|---|
| Sam |
| Nia |
2 rows
Tip: Put WHERE after FROM. The order of SQL clauses is a recipe, not a free-for-all.
Test yourself
Three quick questions made just for this lesson. Earn 10 XP per correct answer.