The BETWEEN operator is used in a WHERE clause to filter records within a specified range of values.
👉 It selects values between two limits (inclusive).
SELECT column_name
FROM table_name
WHERE column_name BETWEEN value1 AND value2;
BETWEEN includes both boundary values:👉 Equivalent to:
column_name >= value1 AND column_name <= value2
| ID | Name | Age |
|---|---|---|
| 1 | Amit | 18 |
| 2 | Riya | 21 |
| 3 | Rahul | 19 |
| 4 | Neha | 23 |
| 5 | Karan | 20 |
SELECT * FROM Students
WHERE Age BETWEEN 19 AND 21;
Returns all students whose age is between 19 and 21 (inclusive).
BETWEEN can also be used with text (alphabetical range).
SELECT * FROM Students
WHERE Name BETWEEN 'A' AND 'M';
SELECT * FROM Orders
WHERE OrderDate BETWEEN '2024-01-01' AND '2024-12-31';
BETWEEN 10 AND 20
👉 Includes 10 and 20 both
BETWEEN 20 AND 10
👉 This will return no result (invalid range)
You can exclude a range:
SELECT * FROM Students
WHERE Age NOT BETWEEN 19 AND 21;
👉 Returns values outside the range
SELECT * FROM Students
WHERE Age >= 19 AND Age <= 21;
👉 Same as:
WHERE Age BETWEEN 19 AND 21;
| Usage Type | Example | Meaning |
|---|---|---|
| Numbers | Age BETWEEN 10 AND 20 | Range of numbers |
| Strings | Name BETWEEN 'A' AND 'M' | Alphabetical range |
| Dates | Date BETWEEN '2024-01-01' AND '2024-12-31' | Date range |
The BETWEEN operator simplifies range conditions and makes queries: