1

I have a MYSQL database which looks like this:

 ID      | Name    | Product
 --------+---------+----------
 65644   | Charlie | Beer
 65644   | John    | Beer
 65644   | Jan     | Beer
 65644   | Phoebe  | Beer
 65644   | Shaun   | Beer

I would like to output a table using php to look something like this:

 ID      |               Name                | Product
 --------+-----------------------------------+----------
 65644   | Charlie, John, Jan, Phoebe, Shaun | Beer

Currently I've only been able to output it to look like this first table. Any help would be greatly appreciated.

1 Answers1

2

Just use group_concat

SELECT ID, group_concat ( Name ORDER BY Name SEPARATOR ', ' ), Product
FROM YourTable
GROUP BY ID, Product
Juan Carlos Oropeza
  • 47,252
  • 12
  • 78
  • 118