BETWEEN for Ranges
Use BETWEEN for inclusive numeric and date ranges, and know when to prefer explicit >= and < comparisons for half-open intervals.
BETWEEN Is Inclusive
BETWEEN a AND b matches values where x >= a AND x <= b. Both endpoints are inclusive.
SELECT * FROM orders WHERE total BETWEEN 100 AND 500;
-- equivalent to:
SELECT * FROM orders WHERE total >= 100 AND total <= 500;Date Ranges
BETWEEN works on dates and timestamps too:
SELECT * FROM orders
WHERE created_at BETWEEN '2024-01-01' AND '2024-12-31';