I'm agree with second suggestion of RolandoMySQLDBA answer that using UNION
instead of OR
makes the seeking of the results too faster, And also we know:
The default behavior for
UNION
is that duplicate rows are removed from the result. The optionalDISTINCT
keyword has no effect other than the default because it also specifies duplicate-row removal. With the optionalALL
keyword, duplicate-row removal does not occur and the result includes all matching rows from all theSELECT
statements.
And as your requirement I think your dates are in a separate sequence that will not make any duplicate row, So, for avoiding that duplicate-row removal that contains a hidden order by and etc. within it, I suggest you to use UNION ALL
instead of UNION
, like this:
SELECT * FROM table1 WHERE (column >= $date1 AND column < $date1 + interval 1 day)UNION ALLSELECT * FROM table1 WHERE (column >= $date2 AND column < $date2 + interval 1 day)UNION ALL...