1 · Read the data · 12 MIN
Combine conditions without guessing precedence
AND requires both conditions; OR accepts either.
Complex filters are easier to understand when grouped with parentheses. The sample requires both a chosen city and enough points. AND binds more tightly than OR in SQL, but relying on remembered precedence can hide mistakes. Use parentheses to state the intended grouping and evaluate each row explicitly. A row with an unknown city does not satisfy city = Delhi. The next lesson explains why unknown values need a different comparison.
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
- AND
- Both conditions must be true.
- OR
- At least one condition must be true.
- precedence
- The order in which operators are grouped.
Follow the example step by step
- Evaluate city and points as two separate questions for each row.
- Combine with AND and retain only Grace.
- Use parentheses around the city alternatives for the change task.
- For the build task, either one of its two conditions is enough.
| 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 names where city is Delhi OR points is zero, ordered by id. The zero-point learner must be included even with an unknown city.
Read the example
SELECT name FROM learners WHERE city = 'Delhi' AND points >= 30 ORDER BY id;
Check the expected output
[["Grace"]]
Your challenge
Return names where city is Delhi OR points is zero, ordered by id. The zero-point learner must be included even with an unknown city.
Common trap
A missing pair of parentheses can allow rows that should fail another condition.
Further reading: SQLite SELECT reference
Next lesson: Understand unknown values and NULL →