SQL BETWEEN Operator: Complete Guide

In SQL, BETWEEN is a conditional operator used to specify a range. It is used to select a set of values from the given range.

The syntax of the BETWEEN operator is as follows:

SELECT column_name(s)
FROM table_name
WHERE column_name BETWEEN value1 AND value2;

In the above syntax, column_name is the name of the column to filter, table_name is the name of the table to filter, and value1 and value2 are the starting and ending values of the range to be filtered.

For example, if we want to select data of employees from a table named “employees” whose salary values fall between 1000 and 2000, we can use the following SQL statement:

SELECT *
FROM employees
WHERE salary BETWEEN 1000 AND 2000;

This will return employee data from the salary column in the employees table where the value falls between 1000 and 2000.

bannerAds