BETWEEN Operator - SQL
Overview
The BETWEEN Operator in SQL is used to filter the result set within a certain range. It returns true if the value of the expression is within the specified range (inclusive).
Syntax:
SELECT column
FROM table_name
WHERE column1 BETWEEN value1 AND value2
column1 BETWEEN value1 AND value2
checks if the value in column1
is between value1
and value2
, inclusive.
Sample Data:
first_name | salary |
---|---|
Frank | 123000 |
Jane | 135000 |
Ashley | 140000 |
Glenn | 115000 |
Kelly | 125000 |
Richard | 120000 |
George | 105000 |
Kyle | 200000 |
James | 107000 |
Gustavo | 100000 |
Example
In this example, we are returning the first_name and the salary column. We then use the BETWEEN operator to filter the results to only include rows where the salary column is between 100000 and 120000.
Example:
SELECT first_name, salary
FROM company.employees
WHERE salary BETWEEN 100000 AND 120000