SQL Tutorial

SQL BETWEEN Operator – Filter a Range of Values with Examples (2026-27)

The SQL BETWEEN operator is used to filter rows where a column value falls within a specified range — including both the lower and upper boundary values. It works with numbers, text (alphabetical order), and dates, and is one of the most commonly used filtering tools in real-world SQL queries. Instead of writing WHERE Salary >= 5000 AND Salary <= 10000, you can write the cleaner, more readable WHERE Salary BETWEEN 5000 AND 10000. In this step-by-step guide you will learn the full BETWEEN syntax, see five real examples — numbers, NOT BETWEEN, text, dates, and BETWEEN with IN — plus a comparison table and the most common mistakes to avoid.



✅ What is the SQL BETWEEN Operator?

✅ The SQL BETWEEN operator is used in a WHERE clause to filter rows within a range.

✅ It is inclusive — both the start value and end value are included in the result.

✅ It works with numbers, text (alphabetical), and dates.

💡 Real-world example: A payroll report needs all employees earning between ₹5,000 and ₹10,000. Using BETWEEN 5000 AND 10000 is cleaner and more readable than writing >= 5000 AND <= 10000 — and gives identical results.

Sample Employees Table used in all examples:-

Employees
IDNameDepartmentSalaryJoinDate
1ANNIIT100002023-03-15
2POOJAIT900002024-07-01
3RAJHR50002022-11-20
4SUJANHR80002024-01-10
5MEENASales120002023-06-30

✅ SQL BETWEEN Syntax

SELECT column1, column2, ...
FROM table_name
WHERE column_name BETWEEN value1 AND value2;

BETWEEN:- Keyword — placed after the column name in the WHERE clause.

value1:- The lower bound of the range (inclusive).

AND:- Separator between the two range values — required.

value2:- The upper bound of the range (inclusive).

ℹ️ Equivalent expression: WHERE Salary BETWEEN 5000 AND 10000 is exactly the same as WHERE Salary >= 5000 AND Salary <= 10000. BETWEEN is simply cleaner to read and write.

✅ Example 1 – BETWEEN with Numbers (Salary Range)

Find all employees whose salary is between 5000 and 10000 (both values included).

SELECT Query:-

SELECT * FROM Employees
WHERE Salary BETWEEN 5000 AND 10000;

Result:-

Result — Employees with Salary 5000 to 10000
IDNameDepartmentSalaryJoinDate
1ANNIIT100002023-03-15
3RAJHR50002022-11-20
4SUJANHR80002024-01-10
💡 Inclusive boundaries: ANNI (10000) and RAJ (5000) are included because BETWEEN includes both boundary values. POOJA (90000) and MEENA (12000) are outside the range and excluded.

✅ Example 2 – NOT BETWEEN (Exclude a Range)

Find all employees whose salary is OUTSIDE the range 5000 to 10000.

SELECT Query:-

SELECT * FROM Employees
WHERE Salary NOT BETWEEN 5000 AND 10000;

Result:-

Result — Employees Outside Salary Range 5000–10000
IDNameDepartmentSalaryJoinDate
2POOJAIT900002024-07-01
5MEENASales120002023-06-30
ℹ️ NOT BETWEEN is also inclusive of boundaries. Employees with salary exactly 5000 or exactly 10000 are EXCLUDED by NOT BETWEEN — they fall within the range. Only POOJA (90000) and MEENA (12000) are truly outside.

✅ Example 3 – BETWEEN with Text (Alphabetical Range)

Find all employees whose name falls alphabetically between 'ANNI' and 'POOJA'.

SELECT Query:-

SELECT * FROM Employees
WHERE Name BETWEEN 'ANNI' AND 'POOJA';

Result:-

Result — Names Between 'ANNI' and 'POOJA' Alphabetically
IDNameDepartmentSalaryJoinDate
1ANNIIT100002023-03-15
4MEENAHR80002024-01-10
2POOJAIT900002024-07-01
⚠️ Text BETWEEN depends on database collation. Alphabetical sorting can differ between databases and may be case-sensitive. Always test text BETWEEN queries in your specific database environment to verify expected results.

✅ Example 4 – BETWEEN with Dates

Find all employees who joined between January 1, 2023 and December 31, 2023.

SELECT Query:-

SELECT * FROM Employees
WHERE JoinDate BETWEEN '2023-01-01' AND '2023-12-31';

Result:-

Result — Employees Who Joined in 2023
IDNameDepartmentSalaryJoinDate
1ANNIIT100002023-03-15
5MEENASales120002023-06-30
💡 Date format tip: Always use the standard date format 'YYYY-MM-DD' with BETWEEN for consistency across all databases. RAJ joined in 2022 and POOJA/SUJAN joined in 2024 — all outside the 2023 range.

✅ Example 5 – BETWEEN Combined with IN Operator

Find IT or Sales employees whose salary is between 5000 and 15000.

SELECT Query:-

SELECT * FROM Employees
WHERE Salary BETWEEN 5000 AND 15000
  AND Department IN ('IT', 'Sales');

Result:-

Result — IT or Sales Employees with Salary 5000–15000
IDNameDepartmentSalaryJoinDate
1ANNIIT100002023-03-15
5MEENASales120002023-06-30
ℹ️ Explanation: POOJA is in IT but earns 90000 (outside range). SUJAN earns 8000 (in range) but is in HR (not IT/Sales). ANNI and MEENA satisfy both conditions.

✅ BETWEEN vs >= AND <= Comparison

Both give identical results. Choose based on readability preference.

FeatureBETWEEN>= AND <=
ResultIdenticalIdentical
Boundary valuesInclusive (both ends)Inclusive (both ends)
ReadabilityCleaner and shorterMore verbose
Works with numbers✅ Yes✅ Yes
Works with dates✅ Yes✅ Yes
Works with text✅ Yes✅ Yes
NOT versionNOT BETWEEN< value1 OR > value2
💡 Rule of thumb: Use BETWEEN for cleaner, more readable code when filtering a continuous range. Use >= AND <= when you need to mix different columns or more complex conditions in the same WHERE clause.

✅ Key Points to Remember

✅ BETWEEN is inclusive — both boundary values are included in the result.

✅ Works with numbers, text, and dates — one operator for all three data types.

✅ NOT BETWEEN excludes the range — rows equal to the boundaries are also excluded.

✅ BETWEEN = >= AND <= — same result, BETWEEN is just cleaner to write.

✅ Always use single quotes for text and datesBETWEEN 'ANNI' AND 'POOJA' and BETWEEN '2023-01-01' AND '2023-12-31'.

✅ Use standard date format — always write dates as 'YYYY-MM-DD' for compatibility across databases.

✅ Text BETWEEN depends on collation — results may vary by database. Always test in your environment.


✅ Common SQL BETWEEN Mistakes to Avoid

❌ Mistake 1: Writing values in the wrong order
Wrong: WHERE Salary BETWEEN 10000 AND 5000 — most databases return 0 rows when the lower bound is greater than the upper bound.
Correct: WHERE Salary BETWEEN 5000 AND 10000 — always put the smaller value first.
❌ Mistake 2: Forgetting BETWEEN is inclusive
If you need to exclude boundary values, use > and < instead: WHERE Salary > 5000 AND Salary < 10000 excludes 5000 and 10000. BETWEEN always includes them.
❌ Mistake 3: Wrong date format
Wrong: BETWEEN '15-03-2023' AND '30-06-2023' — may fail or give wrong results in many databases.
Correct: BETWEEN '2023-03-15' AND '2023-06-30' — always use YYYY-MM-DD format.
❌ Mistake 4: Missing single quotes around text and date values
Wrong: WHERE Name BETWEEN ANNI AND POOJA
Correct: WHERE Name BETWEEN 'ANNI' AND 'POOJA' — text and date values always need single quotes.

✅ Frequently Asked Questions (FAQ)

What does the SQL BETWEEN operator do?
The SQL BETWEEN operator filters rows where a column value falls within a specified range — inclusive of both the start and end values. It is shorthand for: column >= value1 AND column <= value2.
Is SQL BETWEEN inclusive or exclusive?
SQL BETWEEN is inclusive on both ends. A row where the column value equals the lower bound OR the upper bound IS included in the result. For example, BETWEEN 5000 AND 10000 includes rows with salary = 5000 and salary = 10000.
Can I use SQL BETWEEN with dates?
Yes. SQL BETWEEN works with date values. Example: WHERE JoinDate BETWEEN '2023-01-01' AND '2023-12-31' returns all rows where JoinDate falls within the year 2023 — both boundary dates included. Always use YYYY-MM-DD format.
What is NOT BETWEEN in SQL?
NOT BETWEEN returns rows where the column value falls OUTSIDE the specified range. Example: WHERE Salary NOT BETWEEN 5000 AND 10000 returns employees whose salary is less than 5000 or greater than 10000. Boundary values (5000 and 10000) are excluded.
What is the difference between BETWEEN and >= AND <=?
They return identical results. BETWEEN value1 AND value2 is simply a cleaner, more readable shorthand for column >= value1 AND column <= value2. Both include the boundary values.
Can I use SQL BETWEEN with text values?
Yes. BETWEEN works with text (VARCHAR) columns using alphabetical order. Example: WHERE Name BETWEEN 'ANNI' AND 'POOJA' returns names that fall alphabetically between ANNI and POOJA inclusive. Results depend on the database collation settings.

✍️ About the Author: Pramod Behera

Pramod Behera is a SAP and SQL educator with 10+ years of experience in enterprise software and database systems. He founded LearnToSAP.com to help beginners learn SAP and SQL concepts through clear, practical, real-world examples. His tutorials have helped thousands of students and IT professionals across India and beyond.