Is there a performance difference between using a BETWEEN clause or using <= AND >= comparisons?
i.e. these two queries:
SELECT * FROM table WHERE year BETWEEN '2005' AND '2010';
...and
SELECT * FROM table WHERE year >= '2005' AND year <= '2010';
In this example, the year column is VARCHAR2(4) with an index on it.
Between is technically greater than and equal to PLUS less than and equal to.
>= (Greater Than or Equal To) (Transact-SQL) - SQL Server | Microsoft Docs.
From a maintainability perspective, BETWEEN is probably better. The BETWEEN predicate is easier to understand and code than the equivalent combination of the less than or equal to predicate (<=) and the greater than or equal to predicate (>=).
The BETWEEN command is used to select values within a given range. The values can be numbers, text, or dates. The BETWEEN command is inclusive: begin and end values are included.
There is no difference.
Note that BETWEEN
is always inclusive and sensitive to the order of the arguments.
BETWEEN '2010' AND '2005'
will never be TRUE
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With