1
我有以下表格:双重结果与双JOIN在MySQL
产品
- 字段:ID,标题
- 值:(1, '产品1')
表1
个- 字段:ID,idProduct
- 值:(1,1),(2,1)
表2
- 字段: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
见http://stackoverflow.com/问题/ 8872351/mysql的组-CONCAT上双联接 – AlexL 2014-11-03 17:57:33