BETWEEN in MySQL — How It Works

What the MySQL BETWEEN function does, with an example.

Published October 23, 2026

BETWEEN a AND b tests whether a value lies within an inclusive range. It works for numbers, dates and strings.

How it works

For datetime columns, remember BETWEEN includes both ends, so midnight boundaries matter.

Try it in MySQL

SELECT * FROM products WHERE price BETWEEN 10 AND 20
10 ≤ price ≤ 20
SELECT * FROM orders WHERE created_at BETWEEN '2026-11-01' AND '2026-11-30 23:59:59'
November
SELECT * FROM t WHERE x NOT BETWEEN 1 AND 5
outside range

Practical examples

Example 1

SELECT * FROM products WHERE price BETWEEN 10 AND 20;
-- 10 ≤ price ≤ 20

Example 2

SELECT * FROM orders WHERE created_at BETWEEN '2026-11-01' AND '2026-11-30 23:59:59';
-- November

Example 3

SELECT * FROM t WHERE x NOT BETWEEN 1 AND 5;
-- outside range

Use it in a real query

SELECT * FROM products WHERE price BETWEEN 10 AND 20;

Common mistakes

  • Expecting an exclusive upper bound.
  • Date-only upper bound missing the last day's times.
  • Swapped bounds returning no rows.

Key takeaways

  • BETWEEN in one line: BETWEEN a AND b tests whether a value lies within an inclusive range.
  • Try queries in a test database first.
  • Check NULL handling and data types.

FAQ

Half-open ranges?

Use >= start AND < end for datetimes.

Does BETWEEN work in other databases?

Most have an equivalent, but names and syntax vary between MySQL, PostgreSQL, SQL Server and SQLite.

More SQL articles