How do you use the BETWEEN operator in SQL to filter results based on a range of values?
How do you use the BETWEEN operator in SQL to filter results based on a range of values?
331
30-Jun-2023
Updated on 01-Jul-2023
Aryan Kumar
01-Jul-2023The BETWEEN operator in SQL is used to filter results based on a range of values. The syntax for the BETWEEN operator is:
Code snippet
column_nameis the name of the column that you want to filter.low_valueandhigh_valueare the two values that you want to use to define the range.The BETWEEN operator is inclusive, which means that the values
low_valueandhigh_valueare included in the results. For example, the following query will return all the rows from theproductstable where the price is between 10 and 20:Code snippet
You can also use the BETWEEN operator with dates and text values. For example, the following query will return all the rows from the
orderstable where the order date is between January 1, 2023 and April 1, 2023:Code snippet
The BETWEEN operator is a versatile tool that can be used to filter results based on a range of values. It can be used with numeric, date, and text values, and it is inclusive, which means that the values that you specify are included in the results.