BETWEEN — Filter a Range of Values

The BETWEEN keyword allows you to filter rows where a column value is within a range.
It works for numbers, dates, and even text (alphabetical ranges).


Syntax

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

This returns rows where the column value is greater than or equal to value1 and less than or equal to value2.


Example 1: Employees aged between 25 and 30

SELECT name, age FROM employees
WHERE age BETWEEN 25 AND 30;

This returns employees whose age is between 25 and 30 (inclusive).


Example 2: Department names between 'Finance' and 'IT' (alphabetically)

SELECT name, department FROM employees
WHERE department BETWEEN 'Finance' AND 'IT';

This works because text can be compared alphabetically.


Tip

You can also combine BETWEEN with NOT:

SELECT name, age FROM employees
WHERE age NOT BETWEEN 25 AND 30;

This returns employees whose age is outside the range 25 to 30.


The BETWEEN clause is a simple and powerful way to filter data when working with ranges!