SQL BETWEEN Operator

The BETWEEN operator is used in the WHERE conditions to filter records within the specified range. The range of values can be strings, numbers, or dates. The range of values must be specified with the AND operator, as shown below.

 

Syntax:

SELECT * FROM table 
WHERE column 
BETWEEN begin_value AND end_value

 

Example Database:

This is  employee  table.

id name salary hire date
1 Kailash 20000 2022-12-10
2 Amit 5000 2022-07-15
3 Siddarth 15000 2022-03-23
4 Vikas 30000 2022-08-20

 


 

BETWEEN Operator

Exmaple: The salary column is used with the BETWEEN operator to filter records. The salary  BETWEEN 10000 to 20000; specifies that the values in the salary column should be between 10000 and 20000 (inclusive of both values). The below query will display the following result.

Query:

SELECT *
FROM employee
WHERE salary BETWEEN 10000 AND 20000;

Result:

id name salary hire date
1 Kailash 20000 2022-12-10
3 Siddarth 15000 2022-03-23

 

BETWEEN Date Range

Exmaple: The following query uses the BETWEEN operator to specify the date range.

Query:

SELECT *
FROM employee
WHERE salary BETWEEN '2022-07-05' and '2018-8-28';

Result:

id name salary hire date
2 Amit 5000 2022-07-15
4 Vikas 30000 2022-08-20