>= AND <= in your WHERE clause. In this chapter, you will learn BETWEEN with numbers, dates, text, and NOT BETWEEN.SQL BETWEEN Syntax
SELECT column1, column2
FROM table_name
WHERE column BETWEEN value1 AND value2;
The BETWEEN operator is inclusive — it includes both value1 and value2 in the results.
We will use this Employees table:
+----+-----------+------------+--------+-----------+
| ID | Name | Department | Salary | City |
+----+-----------+------------+--------+-----------+
| 1 | Priya K. | Sales | 55000 | Mumbai |
| 2 | John D. | Marketing | 62000 | London |
| 3 | Arun M. | IT | 78000 | Delhi |
| 4 | Emma W. | Sales | 51000 | Sydney |
| 5 | Ravi S. | IT | 72000 | Mumbai |
| 6 | Sara L. | HR | 58000 | New York |
+----+-----------+------------+--------+-----------+
BETWEEN with Numbers
SELECT Name, Salary
FROM Employees
WHERE Salary BETWEEN 55000 AND 72000;
+-----------+--------+ | Name | Salary | +-----------+--------+ | Priya K. | 55000 | | John D. | 62000 | | Ravi S. | 72000 | | Sara L. | 58000 | +-----------+--------+
Both 55000 and 72000 are included. This is the same as WHERE Salary >= 55000 AND Salary <= 72000.
NOT BETWEEN
SELECT Name, Salary
FROM Employees
WHERE Salary NOT BETWEEN 55000 AND 72000;
+-----------+--------+ | Name | Salary | +-----------+--------+ | Arun M. | 78000 | | Emma W. | 51000 | +-----------+--------+
BETWEEN with Text
BETWEEN works on text using alphabetical order:
SELECT Name FROM Employees
WHERE Name BETWEEN 'A' AND 'J';
+-----------+ | Name | +-----------+ | Arun M. | | Emma W. | +-----------+
BETWEEN with Dates
BETWEEN is commonly used to filter records within a date range:
SELECT OrderID, OrderDate
FROM Orders
WHERE OrderDate BETWEEN '2026-03-01' AND '2026-03-31';
⚠️ BETWEEN with Dates and Time
If your date column includes a time component (datetime), BETWEEN '2026-03-01' AND '2026-03-31' means between March 1 at 00:00:00 and March 31 at 00:00:00. Records from March 31 at 10:30 AM would be excluded. Use '2026-03-31 23:59:59' or '2026-04-01' with < to be safe.
BETWEEN vs >= AND <=
| BETWEEN | Equivalent |
|---|---|
BETWEEN 50 AND 70 |
>= 50 AND <= 70 |
NOT BETWEEN 50 AND 70 |
< 50 OR > 70 |
BETWEEN is often combined with IN and LIKE operators to create powerful filters. For a complete reference, see the official MySQL comparison operators documentation.
If you work with data regularly, explore our ready-made Dashboard Templates on NextGenTemplates that use SQL-powered data for business reporting.
📺 Visit our YouTube channel @NeoTechNavigators for step-by-step video tutorials and dashboard demos on this topic.
🧪 Try It Yourself
Write a query that finds employees with IDs between 2 and 5 (inclusive), sorted by name.
SELECT ID, Name, Department
FROM Employees
WHERE ID BETWEEN 2 AND 5
ORDER BY Name;
Expected Output:
+----+-----------+------------+ | ID | Name | Department | +----+-----------+------------+ | 3 | Arun M. | IT | | 4 | Emma W. | Sales | | 2 | John D. | Marketing | | 5 | Ravi S. | IT | +----+-----------+------------+
📝 What You Learned in This Chapter
BETWEENfilters values within an inclusive range- It is equivalent to
>= value1 AND <= value2 - Works with numbers, text (alphabetical), and dates
NOT BETWEENexcludes values within the range- Be careful with datetime columns — the time component matters
Frequently Asked Questions
BETWEEN is inclusive on both ends. BETWEEN 10 AND 20 includes rows where the value is 10, 20, and everything in between. Both boundary values are part of the result.'YYYY-MM-DD'). Be cautious with datetime columns — if the column includes time, make sure your range endpoints account for the full day.>= AND <= internally, so performance is identical. BETWEEN is purely a readability improvement — it makes range conditions cleaner and easier to understand at a glance.BETWEEN 10 AND 20 works correctly. BETWEEN 20 AND 10 returns no rows because no value can be simultaneously >= 20 and <= 10.📖 Chapter 18 of 30 — SQL Tutorial on Neotech Navigators



