lesson 05 Filtering & sorting · beginner
Combine conditions
Combine filters with AND, OR and parentheses.
the idea
AND requires both conditions. OR requires either. AND binds more tightly than OR, so parentheses make mixed conditions explicit.
tables in this lesson
The challenges use this data. Each column shows its type underneath; → marks a link to another table.
products4 columns · 6 rows
| idinteger · key | nametext | categorytext | pricereal |
|---|---|---|---|
| 1 | Notebook | Stationery | 12 |
| 2 | Desk lamp | Home | 45 |
| 3 | Keyboard | Tech | 80 |
| 4 | Pen set | Stationery | 8 |
| 5 | Headphones | Tech | 120 |
showing 5 of 6 rows
example
The idea in one query. Press Run to see what it returns; running examples never affects your progress.
SELECT name, price FROM products WHERE category = 'Tech' AND price < 100;
Watch for: Without parentheses, a price filter may apply to only one side of OR.
build it step by step
Each step changes one thing. Run them in order and watch the result change.
Require both conditions. Category and price are separate columns. AND keeps a row only when both are true.
step-1.sqlSELECT name, category, price FROM products;
Run the reference. AND requires both conditions. OR requires either. AND binds more tightly than OR, so parentheses make mixed conditions explicit.
step-2.sqlSELECT name, price FROM products WHERE category = 'Tech' AND price < 100;