SQL Between

The BETWEEN operator filters values within a range. It works with numbers, dates, and text values.

On this page

SQL BETWEEN Operator

The BETWEEN operator selects values within a given range. It works with numeric, date, and text values.

Basic Syntax

SELECT column1
FROM table_name
WHERE column_name BETWEEN value1 AND value2;

Inclusive Behavior

BETWEEN is inclusive. This means both boundary values are included in the result.

Example: Numeric Range

Return products priced between 50 and 100:

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

This is equivalent to:

SELECT name, price
FROM products
WHERE price >= 50 AND price <= 100;

Example: Date Range

Return orders placed in January 2026:

SELECT id, order_date
FROM orders
WHERE order_date BETWEEN '2026-01-01' AND '2026-01-31';

Date Tip

When working with datetime values (including time), be careful with end boundaries. Sometimes using < next_day is safer than relying on inclusive end times.

Example: Text Range

BETWEEN can also work with text values based on alphabetical order:

SELECT name
FROM customers
WHERE name BETWEEN 'A' AND 'M';

NOT BETWEEN

Use NOT BETWEEN to exclude values within a range.

SELECT name, price
FROM products
WHERE price NOT BETWEEN 50 AND 100;

Common Mistakes

  • Forgetting that BETWEEN is inclusive
  • Using BETWEEN with datetime values without considering time
  • Confusing text range behavior with numeric logic

Performance Note

BETWEEN can use indexes efficiently when applied to indexed columns, especially with numeric or date ranges.

Next Step

Continue with SQL Aliases to learn how to rename columns and tables in query results.