我有一个看起来像这样的查询
SELECT
producttemp.*,
GROUP_CONCAT(colors.id) as color,
GROUP_CONCAT(DISTINCT upc.UPC) as upc
FROM producttemp
INNER JOIN productcolor
ON productcolor.productid=producttemp.id
INNER JOIN upc
ON upc.productid=producttemp.id
INNER JOIN colors
ON colors.id=productcolor.colorid
INNER JOIN categorie
ON categorie.id = producttemp.productcategorie
GROUP BY producttemp.id
LIMIT 5
出于某种原因或者说,我进入了结果字段" color"重复值,即" 1,2,1,2"。为什么DISTINCT
不能用于连接的行?有没有机会解决或者我错过了一点?
答案 0 :(得分:1)
在DISTINCT
::
colors.id
SELECT
producttemp.*,
GROUP_CONCAT(DISTINCT colors.id) as color,
GROUP_CONCAT(DISTINCT upc.UPC) as upc
FROM producttemp
INNER JOIN productcolor
ON productcolor.productid=producttemp.id
INNER JOIN upc
ON upc.productid=producttemp.id
INNER JOIN colors
ON colors.id=productcolor.colorid
INNER JOIN categorie
ON categorie.id = producttemp.productcategorie
GROUP BY producttemp.id
LIMIT 5