SQL

Filtering Ranges with BETWEEN

Instead of writing two conditions with AND, you can use BETWEEN to filter a range of values.

The Long Way

SELECT * FROM products
WHERE price >= 10 AND price <= 50;

The Short Way (BETWEEN)

SELECT * FROM products
WHERE price BETWEEN 10 AND 50;

Both queries do the exact same thing — but BETWEEN is cleaner and easier to read.

Key Points About BETWEEN

DetailExplanation
Inclusive<code>BETWEEN 10 AND 50</code> includes both 10 and 50
Works with text<code>WHERE name BETWEEN 'A' AND 'M'</code> (alphabetical range)
Works with dates<code>WHERE order_date BETWEEN '2025-01-01' AND '2025-12-31'</code>
Order mattersThe smaller value must come first

💡 When to Use BETWEEN

  • Filtering prices within a budget range
  • Finding orders within a date range
  • Selecting records within a numeric ID range

⚠️ Common Mistake

BETWEEN 50 AND 10 returns nothing — always put the smaller value first!

Your Task

Find all products with a price between 5 and 100 (inclusive).

query.sql
Loading SQL engine...
Downloading SQL engine… (one-time)

Downloading SQL engine… (one-time)

This runs entirely in your browser and is cached for next time.