Daniyal Ahmed Daniyal Ahmed - 1 month ago 9
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


DAT DAYS
----- -----
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

Try this:

SELECT p_id, GROUP_CONCAT(dat), GROUP_CONCAT(days) FROM calendar GROUP BY p_id