I’m selecting records that have a certain date in a datetime column, but it feels a bit sloppy, and I’m wondering if there’s a better way. My query looks like this:
SELECT *
FROM myTable
WHERE event_datetime
BETWEEN '2012-05-05 00:00:00' AND '2012-05-05 23:59:59'
and it works fine. I’m just wondering if perhaps there’s a better way to do this in mySQL.
Better from what perspective?
One would propose to use
DATE(event_datetime) = '2012-05-05'but it is terribly inefficient.So continue using your solution and make sure
event_datetimecolumn is covered by index