Daniyal Ahmed Daniyal Ahmed - 1 year ago 115
MySQL Question

How to Concatenate 2 rows in Mysql where a certain column is DIstinct

I Have a DB table named calendar where i have events and there dates saved. In the Image below i have dates saved and the p_id's value can be repeated. i need to get a row that will have a distinct p_id and the dates and days would be concatenated. For E.g at the moment i have 2 rows with p_id = 2
i would want a row that will have the following result

----- -----
19 Wednesday
10,26 Monday,Monday

I have been trying to do this since the past 3 hours and couldn't find a valuable solution. I'd be glad if someone could help :)

Image of the Database Table

obe obe
Answer Source

Try this:

SELECT p_id, GROUP_CONCAT(dat), GROUP_CONCAT(days) FROM calendar GROUP BY p_id
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download