How To Use Between In Sql in SQL
How to Use BETWEEN in SQL
The BETWEEN operator is used to filter the result set within a certain range. It selects values between two specified values, including the boundaries.
Syntax:
SELECT columnsFROM table_nameWHERE column_name BETWEEN value1 AND value2;This means
column_name >= value1 AND column_name <= value2.
Example:
Suppose you have a table employees with a salary column. To find employees with salary between 30000 and 60000:
SELECT *FROM employeesWHERE salary BETWEEN 30000 AND 60000;Notes:
BETWEENworks with numbers, dates, and text (alphabetical order).It is inclusive of the boundary values.
To select values outside the range, use
NOT BETWEEN:
SELECT *FROM employeesWHERE salary NOT BETWEEN 30000 AND 60000;If you want examples with dates or other data types, feel free to ask!