The BETWEEN operator in SQL is used to filter results based on a range of values. The syntax for the BETWEEN operator is:
Code snippet
SELECT columns FROM table WHERE column_name BETWEEN low_value AND high_value;
column_name is the name of the column that you want to filter.
low_value and high_value are the two values that you want to use to define the range.
The BETWEEN operator is inclusive, which means that the values low_value and
high_value are included in the results. For example, the following query will return all the rows from the
products table where the price is between 10 and 20:
Code snippet
SELECT * FROM products WHERE price BETWEEN 10 AND 20;
You can also use the BETWEEN operator with dates and text values. For example, the following query will return all the rows from the
orders table where the order date is between January 1, 2023 and April 1, 2023:
Code snippet
SELECT * FROM orders WHERE order_date BETWEEN '2023-01-01' AND '2023-04-01';
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.
Markdown for AI
A clean, structured version of this page for AI assistants and LLMs.
We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge that you have read and understood our
Cookie Policy &
Privacy Policy.
The 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.