我有一个示例数据
mobile(id, name)
mobile(1, 'Nokia')
mobile(2, 'Samsung')
mobile(3, 'Motorola')
和类别
categories(id, name, mobile_id)
categories(1, 'mobile', '1,2,3')
和mysql:
SELECT cat.name as cat_name, GROUP_CONCAT(mobile.name) as mobile_name
FROM `mobile` as mobile
LEFT OUTER JOIN `categories` AS cat ON cat.mobile_id = mobile.id
如何得到这个结果:
(1,"mobile","Nokia,Samsung,Motorola")
最佳答案
您应该尝试添加
GROUP cat.name
在查询末尾
关于php - 使用 GROUP_CONCAT 时出错?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11078816/