;

SQL BETWEEN


In this tutorial, we will learn how to use BETWEEN operator with WHERE clause.

SQL BETWEEN Operator

SQL BETWEEN operator is used to filtering the result-set within a given range. These Value can be numbers, text or dates. It is always used in the WHERE clause.

Syntax - BETWEEN Operator
SELECT column1,column2,...columnN
FROM tableName
WHERE column BETWEEN value1 AND value2;

Example:

Let us consider this table "Employee" for records.

Table Name : Employee

ID EmpName City Country Gender Salary
1 Shankar Delhi India male 25000
2 Sourabh Delhi India male 30000
3 Ranvijay Mumbai India male 15000
4 Kapil Noida India male 25000
5 Shalini Jaipur India female 18000
6 Rakesh Faridabad India male 23000
7 Akshay Mumbai India male 21000
8 Sarah New York US female 76000
9 Rocky Noida India male 28000

Example of BETWEEN Clause

For selecting an employee whose salary falls between a certain range and the range is 18000 and 25000, a query will be:

Example
SELECT *
FROM Employee
WHERE Salary BETWEEN 18000 and 25000;
Output
ID EmpName City Country Gender Salary
1 Shankar Delhi India male 25000
4 Kapil Noida India male 25000
5 Shalini Jaipur India female 18000
6 Rakesh Faridabad India male 23000
7 Akshay Mumbai India male 21000

For selecting an employee whose salary falls not between a certain range and the range is 18000 and 25000

Example
SELECT *
FROM Employee
WHERE Salary NOT BETWEEN 18000 and 25000;
Output
ID EmpName City Country Gender Salary
2 Sourabh Delhi India male 30000
3 Ranvijay Mumbai India male 15000
8 Sarah New York US female 76000
9 Rocky Noida India male 28000