BETWEEN clause versus <= AND >=
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
.
There is no performance difference between the two example queries because BETWEEN
is simply a shorthand way of expressing an inclusive range comparison. When Oracle parses the BETWEEN
condition it will automatically expand out into separate comparison clauses:
ex.
SELECT * FROM table WHERE column BETWEEN :lower_bound AND :upper_bound
...will automatically become:
SELECT * FROM table WHERE :lower_bound <= column AND :upper_bound >= column
Actually it depends on your DBMS engine.
Some database management systems will compute twice your expression (once for each comparison), and only once when you use BETWEEN
.
Actually if the expression can have a non-deterministic result BETWEEN
will have a different behaviour, compare the following in SQLite:
WHERE RANDOM() BETWEEN x AND y -- one random value generatedWHERE RANDOM() >= x AND RANDOM() <= y -- two distinct random values generated
This can be very time consuming if your expression is (for example) a subquery.