The BETWEEN
operator is used to filter the result set within a certain range. It selects values that are between two specified values (inclusive). It can be used with numbers, dates, and even text.
BETWEEN a AND b
includes both a
and b
in the results.
SELECT column_name(s) FROM table_name WHERE column_name BETWEEN value1 AND value2;
Suppose you have a products
table with a column price
. To find products priced between 50 and 150, use:
SELECT product_name, price FROM products WHERE price BETWEEN 50 AND 150;
To select orders made between two dates, for example, between '2024-01-01' and '2024-03-31':
SELECT order_id, order_date FROM orders WHERE order_date BETWEEN '2024-01-01' AND '2024-03-31';
column_name >= value1 AND column_name <= value2
.NOT BETWEEN
to exclude values within the range.
Help others discover Technorank Learning by sharing your honest experience.
Your support inspires us to keep building!