来自两个表的GROUP_CONCAT

时间:2013-12-27 15:16:31

标签: mysql concat

我有这个大选择,问题是来自不同表的2个GROUP_CONCAT。如果我从选择颜色显示normaly删除描述,如果我保持它像这个颜色显示x3次。

SELECT
DISTINCT m.model as model
        ,m.price as price
        ,m.size as size
        ,m.colorsetIDMainBag as mainColor
    ,GROUP_CONCAT(colorset.name) AS color
    ,leather.name AS leather
        ,leather.nameUA AS leatherUA
        ,leather.nameRU AS leatherRU
    ,GROUP_CONCAT(description.descriptionUA) AS descriptionUA
    ,GROUP_CONCAT(description.descriptionRU) AS descriptionRU
    ,GROUP_CONCAT(description.descriptionEN) AS descriptionEN
FROM
        bags as m
        LEFT OUTER JOIN colorpack
        on m.bagsID=colorpack.colorpack
        LEFT OUTER JOIN color
        on colorpack.colorID=color.colorID
        LEFT OUTER JOIN colorset
        on color.colorsetID=colorset.colorsetID
        LEFT OUTER JOIN leather
        on color.leatherID=leather.leatherID

        LEFT OUTER JOIN descriptionpack
        on m.bagsID=descriptionpack.descriptionpack
        LEFT OUTER JOIN description
        on descriptionpack.descriptionID=description.descriptionID

WHERE
        colorpack.colorpack='62'
GROUP BY model

1 个答案:

答案 0 :(得分:4)

尝试

GROUP_CONCAT(DISTINCT colorset.name) AS color

我认为你知道你正在使用GROUP BY的非标准MySQL扩展,这通常会产生不可预测和奇怪的结果。如果您不知道,请阅读此内容。

http://dev.mysql.com/doc/refman/5.1/en/group-by-extensions.html