0Pricing
SQL Academy · Lesson

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';

All lessons in this course

  1. LIKE Patterns and Wildcards
  2. IN and NOT IN for Sets
  3. BETWEEN for Ranges
  4. IS NULL, IS NOT NULL and COALESCE
← Back to SQL Academy