1 · Read the data · 12 MIN
Keep matching rows with WHERE
WHERE keeps a row only when its condition is true.
Selection of columns and filtering of rows are different operations. Here WHERE checks points for every candidate row, while SELECT still chooses the output columns. The operator >= includes the boundary value. A quoted value such as Delhi is text; points is numeric. Filtering happens before ordering the remaining rows. Start with one condition and predict exactly which source rows pass before running it.
Keep the source rows visible. Predict which rows and columns will remain after each operation.
Before you start
No installation. The tables below are loaded automatically for every run; edits do not touch the CodingNeed account database.
New words, explained
- predicate
- A condition deciding whether to keep a row.
- comparison
- A test such as =, < or >=.
- boundary
- A value exactly on a cutoff, such as 20.
Follow the example step by step
- Check points in each source row.
- Keep Ada, Grace and Sam for >= 20.
- Change >= to > and predict why the two boundary rows disappear.
- Use <= for the exercise’s inclusive upper bound.
| id | name | city | points |
|---|---|---|---|
| 1 | Ada | Delhi | 20 |
| 2 | Lin | NULL (unknown) | 0 |
| 3 | Grace | Delhi | 35 |
| 4 | Sam | Pune | 20 |
| learner_id | course |
|---|---|
| 1 | React |
| 1 | SQL |
| 3 | SQL |
You are ready to move on when: Return name and points for learners whose points are at most 20, ordered by id. Include zero.
Read the example
SELECT name, points FROM learners WHERE points >= 20 ORDER BY id;
Check the expected output
[["Ada",20],["Grace",35],["Sam",20]]
Your challenge
Return name and points for learners whose points are at most 20, ordered by id. Include zero.
Common trap
WHERE points < 20 is not the same as at most 20.
Further reading: SQLite SELECT reference
Next lesson: Combine conditions without guessing precedence →