Reputation: 43
I have a table that has a list of events. I would like to join the unit values from multiple rows into one column for display purposes based on a unique value, "incident".
Current data:
Date Time Incident Unit
1/1 1200 1234 101
1/1 1200 1234 102
How I would like to display it:
Date Time Incident Unit
1/1 1200 1234 101, 102
I am using mysql/php.
Thanks!
Upvotes: 1
Views: 106
Reputation:
Try this query:
SELECT `date`, `time`, `incident`, group_concat(`unit`)
from table group by `incident`
Upvotes: 3
Reputation: 1164
Use this query
SELECT date, time, incident, GROUP_CONCAT(unit SEPARATOR ", ") AS unit FROM table GROUP_BY incident
Upvotes: 0