T-SQL Tutorial T-SQL Advanced Database Management T-SQL References

T-SQL - BETWEEN Keyword



The T-SQL (Transact-SQL) BETWEEN keyword is used to specify a range in a WHERE clause of a T-SQL statement. It is a shorthand for >= AND <=. It is a inclusive operator and includes start and end value while specifying the range.

Syntax

The syntax for using BETWEEN operator in T-SQL (Transact-SQL) is given below:

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

Example:

Consider a database containing a table called Employee with the following records:

EmpIDNameCityAgeSalary
1JohnLondon253000
2MarryNew York242750
3JoParis272800
4KimAmsterdam303100
5RameshNew Delhi283000
6HuangBeijing282800

  • To select all records of the Employee table where Salary is between 2800 and 3000, the query is given below.

    SELECT * FROM Employee
    WHERE Salary BETWEEN 2800 AND 3000;
    

    This will produce the result as shown below:

    EmpIDNameCityAgeSalary
    1JohnLondon253000
    3JoParis272800
    5RameshNew Delhi283000
    6HuangBeijing282800

❮ T-SQL Keywords