lesson 04 Filtering & sorting · beginner
Comparisons & ranges
Filter numbers and dates with comparisons and ranges.
the idea
Use >, >=, < and <= to compare values. BETWEEN includes both endpoints. Decide whether the task includes the boundary before choosing an operator.
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 price >= 45;
Watch for: Using > instead of >= drops the boundary row.
build it step by step
Each step changes one thing. Run them in order and watch the result change.
Include the boundary. Look at the prices. A product at exactly 45 stays when the condition uses >=.
step-1.sqlSELECT name, price FROM products ORDER BY price;
Run the reference. Use >, >=, < and <= to compare values. BETWEEN includes both endpoints. Decide whether the task includes the boundary before choosing an operator.
step-2.sqlSELECT name, price FROM products WHERE price >= 45;