BETWEEN
BETWEEN is an operator in SQL that is used to select values within a certain range. The values can be texts, numbers, or dates. It includes the end values specified in the range.
Example
Output
Explanation
The SQL commands above select all records from the Orders
table where OrderDate
is within the range of ‘1996-07-01’ and ‘1996-12-31’, inclusive. The ellipsis in the output represents other rows fitting the criteria that are not shown.
Example
Output
Explanation
The BETWEEN
operator in SQL is used to select values within a given range. The values can be numbers, text, or dates. In the above example, the query selects all records from the employees
table where the salary is between 5000 and 10000, inclusive.
Example
Output
Explanation
The BETWEEN
operator in the above SQL command is used to select all columns from the Employees
table where the hire_date
lies between ‘2001-01-01’ and ‘2002-12-31’. The output demonstrates the results of this query, showing only the employees who were hired in the years 2001 and 2002.
Example
Output
Explanation
The example SQL query retrieves all the rows from the ‘employees’ table where the ‘salary’ column value falls between 30000 and 40000 (both values inclusive).
Example
Output
Explanation
In the given example, the BETWEEN
keyword is used to select all records from the Orders
table where OrderDate
is between the dates ‘2020-01-01’ and ‘2020-12-31’, inclusive. The output shows a subset of the returned rows, displaying the OrderID
, CustomerID
, and OrderDate
.