The BETWEEN operator filters rows where a column value falls within a specific range — from a lower boundary to an upper boundary. It works with numbers, dates, and even text, and it is inclusive on both ends, meaning the boundary values themselves are included in the result.
SELECT columns FROM table_name
WHERE column_name BETWEEN lower_value AND upper_value;
BETWEEN lower AND upper is equivalent to column >= lower AND column <= upper. Both boundary values are included in the results.
Find students whose age is between 21 and 23 (inclusive):
SELECT * FROM students
WHERE age BETWEEN 21 AND 23;
| id | name | city | age |
|---|---|---|---|
| 1 | Rahim Uddin | Dhaka | 22 |
| 3 | Karim Ali | Sylhet | 23 |
| 4 | Nila Akter | Dhaka | 21 |
Students aged 21, 22, and 23 are all included — both boundaries count.
Date ranges are one of the most common uses of BETWEEN in real applications — for example, filtering orders placed within a specific month:
-- Orders placed in June 2025
SELECT * FROM orders
WHERE order_date BETWEEN '2025-06-01' AND '2025-06-30';
-- Users registered in 2024
SELECT * FROM users
WHERE registered_at BETWEEN '2024-01-01' AND '2024-12-31';
DATETIME columns by date range, be aware that BETWEEN '2025-06-30' only covers up to 2025-06-30 00:00:00. To include the entire last day, use AND '2025-06-30 23:59:59' or < '2025-07-01'.
BETWEEN also works on text columns using alphabetical order:
-- Products with names alphabetically between 'C' and 'M'
SELECT name FROM products
WHERE name BETWEEN 'C' AND 'M';
This returns products whose names start with any letter from C to M. Text comparison follows the column's collation (sort order).
NOT BETWEEN returns rows where the value falls outside the specified range:
-- Students whose age is NOT between 21 and 23
SELECT * FROM students
WHERE age NOT BETWEEN 21 AND 23;
| id | name | city | age |
|---|---|---|---|
| 2 | Sara Begum | Chittagong | 20 |
| 5 | Rafi Hossain | Rajshahi | 24 |
Both queries below produce exactly the same result:
-- Using BETWEEN
SELECT * FROM students WHERE age BETWEEN 21 AND 23;
-- Equivalent with comparison operators
SELECT * FROM students WHERE age >= 21 AND age <= 23;
BETWEEN is simply a cleaner way to express the same range condition.
BETWEEN lower AND upper is inclusive — both boundary values are part of the result.DATETIME columns, be precise about the upper boundary to include the full last day.NOT BETWEEN returns rows outside the range.BETWEEN a AND b is equivalent to column >= a AND column <= b.BETWEEN 21 AND 23, not BETWEEN 23 AND 21.= NULL does not work.