【发布时间】:2014-12-30 10:48:04
【问题描述】:
我有以下表格:
产品
- 字段:ID、标题
- 值:(1,'Product 1')
table1
- 字段:id、idProduct
- 值:(1,1),(2,1)
table2
- 字段:id、idProduct
- 值:(3,1),(4,1)
还有以下查询:
SELECT
p.*,
GROUP_CONCAT(t1.id ORDER BY t2.id),
GROUP_CONCAT(t2.id ORDER BY t2.id)
FROM
products p
JOIN table1 t1 ON p.id=t1.idProduct
JOIN table2 t2 ON p.id=t2.idProduct
GROUP BY
p.id
预期结果是:
1 | Product 1 | 1,2 | 3,4
不幸的是我得到了:
1 | Product 1 | 1,1,2,2 | 3,3,4,4
【问题讨论】:
标签: mysql join group-concat