Reputation: 8106
I have a Table that has rows of dates
& times
. I want to produce a list of all the times for each unique date in the table
.
Here is the table:
DATE TIME
2000-01-01 09:00:00
2000-01-01 13:00:00
2000-07-18 09:00:00
2000-07-18 13:00:00
2000-12-31 10:31:00
2000-12-31 14:17:00
2000-12-31 21:42:00
I would the result set to look like this:
2000-01-01, 09:00:00, 13:00:00
2000-07-18, 09:00:00, 13:00:00
2000-12-31, 10:31:00, 14:17:00, 21:42:00
Is it possible?
Amended: Is it also possible to produce this result set in 1 query?
2000-01-01, 2000-07-18, 09:00:00, 13:00:00
2000-12-31, 10:31:00, 14:17:00, 21:42:00
Upvotes: 0
Views: 56
Reputation: 16953
You need GROUP_CONCAT: https://dev.mysql.com/doc/refman/5.0/en/group-by-functions.html#function_group-concat
Something like:
SELECT DATE, GROUP_CONCAT(TIME) FROM tablename GROUP BY DATE
Upvotes: 1
Reputation: 780724
SELECT Date, GROUP_CONCAT(Time) AS Times
FROM YourTable
GROUP BY Date
Upvotes: 1