SolveWithSQL

SQL Beginner Challenge 14: Filter Ranges with BETWEEN

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_nametypedescription
product_idINTEGERUnique product ID
nameTEXTProduct name
categoryTEXTProduct category
priceDECIMALProduct price

Sample Data

product_idnamecategoryprice
101Wireless MouseAccessories24.99
102Mechanical KeyboardAccessories89.00
10327-inch MonitorDisplays229.99
104USB-C HubAccessories34.50
105Laptop StandWorkspace39.99
106WebcamAccessories59.99

Your Task

Write a SQL query that returns:

  • name
  • price

…but only for products where price is between 30 and 100.

Expected Output

nameprice
USB-C Hub34.50
Laptop Stand39.99
Webcam59.99
Mechanical Keyboard89.00

Constraints

  • Use BETWEEN
  • Do not use SELECT *
  • Return only name and price

Hint (Optional)

BETWEEN is inclusive, meaning it includes both endpoints:

  • BETWEEN 30 AND 100 includes 30 and 100.

SELECT
name,
price
FROM products
WHERE price BETWEEN 30 AND 100;

Explanation

  • WHERE price BETWEEN 30 AND 100 filters rows to only those within the range.
  • Because BETWEEN is inclusive, boundary values are included if they exist.
  • This is commonly used for price bands, date ranges, and thresholds.

Common Mistakes

  1. Assuming BETWEEN is exclusive
    • It is inclusive.
  2. Reversing the range WHERE price BETWEEN 100 AND 30 -- ❌ usually returns no rows
  3. Using BETWEEN for string values without understanding sorting
    • Works, but depends on collation/order.

Optional Extension (Mini Bonus)

Try:

  1. Filter products priced between 50 and 200
  2. Filter products priced NOT between 30 and 100
  3. Combine BETWEEN with ORDER 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.