Overview
Find cheap books and games: combine conditions with AND and OR, and use parentheses so the query means what you say.
- AND, OR
- AND is evaluated before OR
- Parentheses group conditions
Short Course
AND and OR combine conditions. Trap: AND is evaluated before OR, so
a OR b AND c means a OR (b AND c). Add parentheses to say what you mean.
-- cheap books or games?
WHERE category = 'book' OR category = 'game' AND price < 20
-- really means: every book, plus the cheap games
WHERE (category = 'book' OR category = 'game') AND price < 20
Task
Return the name of every product in the book or game category that costs
less than 20, ordered by name. In the database below, Atlas is a book but too
expensive.
Database
Sample data from the first test. The other tests use different rows, so write a query, not a list of answers.
| idINTEGER | nameTEXT | categoryTEXT | priceREAL |
|---|---|---|---|
| 1 | Atlas | book | 35.0 |
| 2 | Chess | game | 15.0 |
| 3 | Dune | book | 9.5 |
| 4 | Lamp | home | 12.0 |
| 5 | Uno | game | 8.0 |
| 6 | Zelda | game | 59.0 |
Test Suites
Pending
Next
Output