Lesson 12 of 30
40%
AND, OR, NOT
AND, OR, and NOT combine tests.
AND needs every test to be true.
OR needs at least one test to be true.
NOT flips a test.
AND
Both city and age must match.
sql
Result
| name |
|---|
| Ada |
1 row
OR
Either city is fine.
sql
Result
| name | city |
|---|---|
| Ada | London |
| Omar | Cairo |
2 rows
NOT
sql
Result
| name | city |
|---|---|
| Sam | Kenya |
| Lin | Taipei |
| Omar | Cairo |
| Nia | Unknown |
4 rows
Parentheses
AND is tighter than OR. Use parentheses so the mix is obvious.
sql
Result
| name | city | age |
|---|---|---|
| Ada | London | 12 |
| Omar | Cairo | 12 |
2 rows
Tip: If a WHERE feels confusing, write each test on its own line.
Test yourself
Three quick questions made just for this lesson. Earn 10 XP per correct answer.