4. WHERE: Keep Only the Rows You Need
4.5 IN, BETWEEN and LIKE (% and _) with Real Filters
Why. Lists, ranges and patterns cover most analyst filters.
What. IN lists values. BETWEEN is inclusive range. LIKE uses % (any) and _ (one char).
How. WHERE city IN ('Pune','Mumbai') / amount BETWEEN 500 AND 900 / name LIKE 'A%'
Steps
- Cities in a list with IN.
- Amounts BETWEEN 600 AND 1000.
- Customer names starting with P.
Examples
Example 1 · dataset: raja_coffee
SELECT order_id, city, amount_inr
FROM orders
WHERE city IN ('Pune','Goa')
AND amount_inr BETWEEN 600 AND 1000;Output
| order_id | city | amount_inr |
|---|---|---|
| 1001 | Pune | 840.0 |
| 1003 | Goa | 890.0 |
| 1006 | Pune | 890.0 |
| 1009 | Pune | 700.0 |
| 1021 | Pune | 620.0 |
| 1024 | Pune | 720.0 |
Meaning. Pune or Goa, mid-size amounts.
Example 2 · dataset: raja_coffee
SELECT name, city FROM customers WHERE name LIKE 'P%';Output
| name | city |
|---|---|
| Priya Deshmukh | Kolhapur |
Meaning. Names starting with P (Priya pattern).
Ravindra Bagale's Tip
BETWEEN is inclusive on both ends — 600 and 1000 both qualify.
Ravindra Bagale's Tip – मराठी
BETWEEN दोन्ही टोकांना समावेशक — 600 आणि 1000 दोन्ही मोडतात.
Ravindra Bagale's Tip – हिंदी
BETWEEN दोनों सिरों पर inclusive है — 600 और 1000 दोनों गिने जाते हैं।