100

My query is this. I have a bunch of entries and i want to group them by date. But instead of having date in my database, I have a datetime field. What do I do?

select * from follow_queue group by follow_date cast follow_date as date

That's not working.

BenMorel
  • 31,815
  • 47
  • 169
  • 296
Zack Burt
  • 7,866
  • 10
  • 52
  • 80
  • 2
    Try: `select * from follow_queue group by cast(follow_date as date)` first. – NawaMan Sep 23 '09 at 22:16
  • 3
    you don't need to cast, just use the DATE() function – markus Sep 23 '09 at 22:56
  • Doesn't the DATE() function cast the datetime to a string? Sure, it works for grouping by date, but I think NawaMan's answer is more correct based on the phrasing of the question – DJDave Feb 09 '16 at 13:54

1 Answers1

198

Use DATE() function:

select * from follow_queue group by DATE(follow_date)
rink.attendant.6
  • 40,889
  • 58
  • 100
  • 149
ChssPly76
  • 97,371
  • 24
  • 203
  • 192