Checking your session…
Module 08: Data Filtering and Operators

8.5 BETWEEN

Level: 8 | Version: v1.1 | Author: Meptrasoft

Overview

BETWEEN is used to filter values within a range.

The starting and ending values are both included.

SQL
SELECT *
FROM employees
WHERE salary BETWEEN 20000 AND 50000;

This returns employees whose salary is:

TEXT
>= 20000
AND
<= 50000

BETWEEN → Check whether a value falls within a range.

SQL BETWEEN — Filter a Range: inclusive boundary filtering
Figure 1: BETWEEN filters values within an inclusive range, including both the starting and ending values.

Practice Table

This topic reuses the employees table from 8.1 The WHERE Clause.

emp_id emp_name dept_id salary
1 John Smith 10 45000
2 Emma Brown 20 60000
3 Samuel Reed 10 32000
4 Anderson 30 55000
5 Sarah Wilson 20 48000
6 Tom Watson 10 51000

BETWEEN with Numbers

Find employees whose salary is between 30000 and 50000:

SQL
SELECT *
FROM employees
WHERE salary BETWEEN 30000 AND 50000;

This includes salaries of exactly 30000 and 50000.

BETWEEN is inclusive.


BETWEEN with Dates

BETWEEN can also be used with dates.

For example:

SQL
SELECT *
FROM employees
WHERE join_date BETWEEN '2026-01-01' AND '2026-06-30';

This selects dates within the specified range, including the boundary dates.


BETWEEN vs Comparison Operators

This:

SQL
WHERE salary BETWEEN 30000 AND 50000

is equivalent to:

SQL
WHERE salary >= 30000
  AND salary <= 50000

BETWEEN is often easier to read when working with ranges.


NOT BETWEEN

NOT BETWEEN can be used to exclude a range.

SQL
SELECT *
FROM employees
WHERE salary NOT BETWEEN 30000 AND 50000;

This returns salaries below 30000 or above 50000.

NOT BETWEEN → Outside the specified range.


NULL Values

If the value being tested is NULL, the BETWEEN condition does not evaluate to TRUE.

For example:

TEXT
salary = NULL

does not match:

SQL
WHERE salary BETWEEN 30000 AND 50000

NULL requires separate handling with IS NULL or IS NOT NULL.


Common Beginner Mistakes

✗ Mistake ✓ Correct Understanding
BETWEEN excludes the boundary values Both boundary values are included
BETWEEN 30000 AND 50000 means only values strictly inside 30000 and 50000 are included
BETWEEN works only with numbers It can also be used with comparable values such as dates
BETWEEN changes the stored data It only filters query results
NOT BETWEEN means equal to the boundaries It means outside the specified range

Placement Quick Points

TEXT
BETWEEN
→ RANGE FILTER

START
→ INCLUDED

END
→ INCLUDED

NOT BETWEEN
→ OUTSIDE THE RANGE
  • BETWEEN filters values within a range.
  • The start and end values are included.
  • BETWEEN can be used with numbers, dates, and other comparable values.
  • NOT BETWEEN excludes the specified range.
  • NULL values require separate handling.

Interview Questions

What is BETWEEN in SQL?

BETWEEN filters values that fall within a specified range.

Is BETWEEN inclusive?

Yes. Both the lower and upper boundary values are included.

What is the equivalent of BETWEEN?
SQL
salary BETWEEN 30000 AND 50000

is equivalent to:

SQL
salary >= 30000
AND salary <= 50000
Can BETWEEN be used with dates?

Yes.

SQL
WHERE join_date BETWEEN '2026-01-01' AND '2026-06-30'
What is NOT BETWEEN?

It selects values outside the specified range.

Does BETWEEN include NULL?

No. A NULL value does not satisfy a BETWEEN condition.


Practice & Hands-On Exercises

Using the employees table:

  1. Find employees with salary between 30000 and 50000:
SQL
SELECT * FROM employees WHERE salary BETWEEN 30000 AND 50000;
  1. Find employees with salary between 40000 and 60000:
SQL
SELECT * FROM employees WHERE salary BETWEEN 40000 AND 60000;
  1. Find employees whose salary is not between 30000 and 50000:
SQL
SELECT * FROM employees WHERE salary NOT BETWEEN 30000 AND 50000;
  1. Write the equivalent >= and <= condition for a BETWEEN query:
SQL
SELECT * FROM employees WHERE salary >= 30000 AND salary <= 50000;
  1. Explain why BETWEEN includes both boundary values.

💡 Tip: Test your queries using the in-browser interactive runner above.


Key Takeaway

TEXT
BETWEEN 30000 AND 50000
        ↓
>= 30000 AND <= 50000

BETWEEN is used to filter values within an inclusive range, including both the starting and ending values.

End of BETWEEN