This question already has answers here:
Can I concatenate multiple MySQL rows into one field?
(11个答案)
三年前关闭。
我有一个MYSQL数据库,如下所示:
 ID      | Name    | Product
 --------+---------+----------
 65644   | Charlie | Beer
 65644   | John    | Beer
 65644   | Jan     | Beer
 65644   | Phoebe  | Beer
 65644   | Shaun   | Beer

我想使用php输出一个表,如下所示:
 ID      |               Name                | Product
 --------+-----------------------------------+----------
 65644   | Charlie, John, Jan, Phoebe, Shaun | Beer

目前,我只能输出它看起来像第一个表。任何帮助都将不胜感激。

最佳答案

使用group_concat

SELECT ID, group_concat ( Name ORDER BY Name SEPARATOR ', ' ), Product
FROM YourTable
GROUP BY ID, Product

关于php - MySQL组一起复制[duplicate],我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/35635498/

10-11 03:06