Are the range boundries included in MySQL's between? For example if I do
date between '2013/12/02' AND '2013/12/01'
will they be included as well? Also which one is better? either I should use BETWEEN
or should I rely on <=
and >=
?
Are the range boundries included in MySQL's between? For example if I do
date between '2013/12/02' AND '2013/12/01'
will they be included as well? Also which one is better? either I should use BETWEEN
or should I rely on <=
and >=
?
As per the manual:
If expr is greater than or equal to min and expr is less than or equal to max, BETWEEN returns 1, otherwise it returns 0. This is equivalent to the expression (min <= expr AND expr <= max) if all the arguments are of the same type. Otherwise type conversion takes place according to the rules described in Section 12.2, “Type Conversion in Expression Evaluation”, but applied to all the three arguments.
Between has better efficiency. It fixes an issue where MYSQL may have unneeded reevaluations of the conditions.
See this answer: Why use the BETWEEN operator when we can do without it?
If your date values are actually datetime values, and the time component is not always '00:00:00', then neither suggestion in the question is good. You want a variation of the second one. Specifically, you want
where yourfield >= your start date
and your field < the day after your end date