1

我有一个看起来像这样的查询

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

出于某种原因或其他原因,我在结果字段“颜色”中得到重复值,即“1,2,1,2”。为什么不适DISTINCT用于连接的行?有没有机会解决或者我错过了一点?

4

1 回答 1

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
于 2013-10-27T13:16:12.210 回答