SQL BETWEEN
SQL

SQL BETWEEN — How to Filter Values in a Range

CHAPTER 18 of 30 SQL Tutorial — Free Course on Neotech Navigators
The SQL BETWEEN operator filters rows where a value falls within a specified range — including both endpoints. It is a cleaner alternative to using >= AND <= in your WHERE clause. In this chapter, you will learn BETWEEN with numbers, dates, text, and NOT BETWEEN.

SQL BETWEEN Syntax

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:

TABLE: Employees
+----+-----------+------------+--------+-----------+
| 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

SQL — Salary between 55000 and 72000
SELECT Name, Salary
FROM Employees
WHERE Salary BETWEEN 55000 AND 72000;
✓ OUTPUT
+-----------+--------+
| 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

SQL
SELECT Name, Salary
FROM Employees
WHERE Salary NOT BETWEEN 55000 AND 72000;
✓ OUTPUT
+-----------+--------+
| Name      | Salary |
+-----------+--------+
| Arun M.   | 78000  |
| Emma W.   | 51000  |
+-----------+--------+

BETWEEN with Text

BETWEEN works on text using alphabetical order:

SQL
SELECT Name FROM Employees
WHERE Name BETWEEN 'A' AND 'J';
✓ OUTPUT
+-----------+
| Name      |
+-----------+
| Arun M.   |
| Emma W.   |
+-----------+

BETWEEN with Dates

BETWEEN is commonly used to filter records within a date range:

SQL — Orders in March 2026
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.

ANSWER
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

  • BETWEEN filters values within an inclusive range
  • It is equivalent to >= value1 AND <= value2
  • Works with numbers, text (alphabetical), and dates
  • NOT BETWEEN excludes values within the range
  • Be careful with datetime columns — the time component matters

Frequently Asked Questions

Is SQL BETWEEN inclusive or exclusive?
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.
Can I use BETWEEN with dates?
Yes. BETWEEN works well with date columns. Use the format your database expects (usually 'YYYY-MM-DD'). Be cautious with datetime columns — if the column includes time, make sure your range endpoints account for the full day.
Is BETWEEN faster than >= AND <=?
No. Most databases convert BETWEEN into >= AND <= internally, so performance is identical. BETWEEN is purely a readability improvement — it makes range conditions cleaner and easier to understand at a glance.
Does the order of values in BETWEEN matter?
Yes. The smaller value must come first. BETWEEN 10 AND 20 works correctly. BETWEEN 20 AND 10 returns no rows because no value can be simultaneously >= 20 and <= 10.
Can BETWEEN handle NULL values?
If the column value is NULL, BETWEEN returns UNKNOWN (which acts like FALSE), so the row is excluded. NULL values are never included in BETWEEN results. Use IS NULL separately to handle missing data.

📖 Chapter 18 of 30 — SQL Tutorial on Neotech Navigators

PK
Meet PK, the founder of NeotechNavigators.com! With over 15 years of experience in Data Visualization, Excel Automation, and dashboard creation. PK is a Microsoft Certified Professional who has a passion for all things in Excel. PK loves to explore new and innovative ways to use Excel and is always eager to share his knowledge with others. With an eye for detail and a commitment to excellence, PK has become a go-to expert in the world of Excel. Whether you're looking to create stunning visualizations or streamline your workflow with automation, PK has the skills and expertise to help you succeed. Join the many satisfied clients who have benefited from PK's services and see how he can take your data analysis skills to the next level!
https://neotechnavigators.com