Is there any better performance when querying in (particularly) mysql of the following:
SELECT * FROM `table` WHERE `unix_date` BETWEEN 1291736700 AND 129173
BETWEEN
shows clearer intent and reads better (something SQL set out to do).
From the documentation:
expr
BETWEENmin
ANDmax
If
expr
is greater than or equal tomin
andexpr
is less than or equal tomax
, BETWEEN returns 1, otherwise it returns 0. This is equivalent to the expression (min
<=expr
ANDexpr
<=max
) if all the arguments are of the same type. Otherwise type conversion takes place according to the rules described in Section 11.2, “Type Conversion in Expression Evaluation”, but applied to all the three arguments.
So it really is just syntax sugar.
As I recall, there's no difference. But see for yourself if:
explain plan for
SELECT * FROM `table` WHERE `unix_date` BETWEEN 1291736700 AND 1291737300
and:
explain plan for
SELECT * FROM `table` WHERE `unix_date` >= 1291736700 AND `unix_date` <= 1291737300
produce the same plans.
The three following statement will produce the same result:
i BETWEEN x AND y
x <= i AND i <= Y
i >= x AND i <= Y
But in configuration 3 mysql might (depending on your indexes) use different indexes: order matters and you should be testing with EXPLAIN query to see the difference