Difficulty: Beginner
Estimated time: 10–15 minutes
SQL concepts: BETWEEN, numeric ranges, inclusive boundaries
Goal: Filter rows that fall within a value range.
The Scenario
A product manager asks:
“Show me all products priced between 30 and 100.”
This is a classic filtering task for pricing, dates, IDs, and many other values.
SQL provides a clean way to do this using BETWEEN.
Database Table
products
| column_name | type | description |
|---|---|---|
| product_id | INTEGER | Unique product ID |
| name | TEXT | Product name |
| category | TEXT | Product category |
| price | DECIMAL | Product price |
Sample Data
| product_id | name | category | price |
|---|---|---|---|
| 101 | Wireless Mouse | Accessories | 24.99 |
| 102 | Mechanical Keyboard | Accessories | 89.00 |
| 103 | 27-inch Monitor | Displays | 229.99 |
| 104 | USB-C Hub | Accessories | 34.50 |
| 105 | Laptop Stand | Workspace | 39.99 |
| 106 | Webcam | Accessories | 59.99 |
Your Task
Write a SQL query that returns:
nameprice
…but only for products where price is between 30 and 100.
Expected Output
| name | price |
|---|---|
| USB-C Hub | 34.50 |
| Laptop Stand | 39.99 |
| Webcam | 59.99 |
| Mechanical Keyboard | 89.00 |
Constraints
- Use
BETWEEN - Do not use
SELECT * - Return only
nameandprice
Hint (Optional)
BETWEEN is inclusive, meaning it includes both endpoints:
BETWEEN 30 AND 100includes 30 and 100.
SELECT
name,
price
FROM products
WHERE price BETWEEN 30 AND 100;
Explanation
WHERE price BETWEEN 30 AND 100filters rows to only those within the range.- Because
BETWEENis inclusive, boundary values are included if they exist. - This is commonly used for price bands, date ranges, and thresholds.
Common Mistakes
- Assuming BETWEEN is exclusive
- It is inclusive.
- Reversing the range
WHERE price BETWEEN 100 AND 30 -- ❌ usually returns no rows - Using BETWEEN for string values without understanding sorting
- Works, but depends on collation/order.
Optional Extension (Mini Bonus)
Try:
- Filter products priced between 50 and 200
- Filter products priced NOT between 30 and 100
- Combine
BETWEENwithORDER BY price
Next Challenge
Beginner Challenge #15: Match Patterns with LIKE
🔗 View reference solution on GitHub
(After you’ve tried the challenge)
Want more practical SQL challenges?
Subscribe to the Solve With SQL newsletter and get new problems delivered to your inbox.