BETWEEN

The SQL BETWEEN Operator

BETWEEN selects values within a range. The values can be numbers, text or dates. Both ends are included.

SELECT column_name(s)
FROM table_name
WHERE column_name BETWEEN value1 AND value2;

Numbers

Example

Products priced between 5 and 10:

SELECT ProductName, Price FROM Products
WHERE Price BETWEEN 5 AND 10;

Result: 3 rows

ProductNamePrice
Green Tea 100 bags6.75
Olive Oil 1L9.99
Almonds 500g8.25

NOT BETWEEN

Example

Products priced outside the range 5 to 10:

SELECT ProductName, Price FROM Products
WHERE Price NOT BETWEEN 5 AND 10;

Result: 3 rows

ProductNamePrice
Basmati Rice 5kg12.5
Dark Chocolate3.49
Espresso Beans 1kg18

Dates

Example

Orders placed in February 2024:

SELECT * FROM Orders
WHERE OrderDate BETWEEN '2024-02-01' AND '2024-02-29';

Result: 2 rows

OrderIDCustomerIDEmployeeIDOrderDateAmount
103222024-02-03412
104132024-02-1856.25

Note: If the column also stores a time (DATETIME), BETWEEN '2024-02-01' AND '2024-02-29' misses everything after midnight on the 29th. For date-times, prefer OrderDate >= '2024-02-01' AND OrderDate < '2024-03-01'.

Text

Example

Customer names alphabetically between B and E (E itself is excluded unless the name is exactly "E"):

SELECT CustomerName FROM Customers
WHERE CustomerName BETWEEN 'B' AND 'E'
ORDER BY CustomerName;

Result: 3 rows

CustomerName
Blue Harbor Foods
Cedar & Co
Delta Mart