The BETWEEN… AND operators in SQL is used to select in-between values from the given range values. The values can be numbers, text, or dates.
Syntax
SELECT column_name
FROM table_name
WHERE column_name BETWEEN value1 AND value2;
Here, value1 is the lower limit and value2 is the upper limit.
Example: Numbers
Suppose we have an Employees table:
| ID | Name | Salary |
|---|---|---|
| 1 | Ayush | 30000 |
| 2 | Mayank | 45000 |
| 3 | Shivansh | 60000 |
| 4 | Sakshi | 75000 |
To find employees whose salary is between 40,000 and 70,000:
SELECT *
FROM Employees
WHERE Salary BETWEEN 40000 AND 70000;
Output:
| ID | Name | Salary |
|---|---|---|
| 2 | Mayank | 45000 |
| 3 | Shivansh | 60000 |
BETWEEN with Dates
BETWEEN can also be used with dates:
SELECT *
FROM Orders
WHERE OrderDate BETWEEN '2026-01-01' AND '2026-01-31';
This selects orders between January 1 and January 31, inclusive.
NOT BETWEEN
To find values outside a range, use NOT BETWEEN:
SELECT *
FROM Employees
WHERE Salary NOT BETWEEN 40000 AND 70000;
This returns employees whose salary is less than 40,000 or greater than 70,000.