There is a request:

SELECT GROUP_CONCAT(DISTINCT wh.uid ORDER BY wh.id) as property_uid, GROUP_CONCAT(DISTINCT wh.folder_name ORDER BY wh.id) as property, GROUP_CONCAT(DISTINCT pr.uid) FROM warehouse_folders wh RIGHT JOIN product_property pp ON wh.uid = pp.property_uid LEFT JOIN products pr ON pr.uid = pp.product_uid WHERE wh.parent_folder_uid IN (160819192400136, 160819192400134) GROUP BY pr.uid ORDER BY property ; 

The result of which:

Result of the executed request

Problem: the property field has the same name - "Green, May", but a different product ID (right column). Because GROUP BY pr.uid it throws them in different lines.

What I want as a result: remove the repetition (ie, -1 line), and the product id , which has the same property , put next.

How to do it?

  • If you are given an exhaustive answer, mark it as correct (a daw opposite the selected answer). - Nicolas Chabanovsky

1 answer 1

 SELECT GROUP_CONCAT(DISTINCT t.property_uid ) AS tproperty_uid, GROUP_CONCAT(DISTINCT t.property ) AS tproperty, GROUP_CONCAT(DISTINCT t.pr_uid) FROM ( SELECT GROUP_CONCAT(DISTINCT wh.uid ORDER BY wh.id) AS property_uid, GROUP_CONCAT(DISTINCT wh.folder_name ORDER BY wh.id) AS property, GROUP_CONCAT(DISTINCT pr.uid) AS pr_uid FROM warehouse_folders wh RIGHT JOIN product_property pp ON wh.uid = pp.property_uid LEFT JOIN products pr ON pr.uid = pp.product_uid WHERE wh.parent_folder_uid IN (160819192400136, 160819192400134) GROUP BY pp.product_uid ORDER BY property ) AS T GROUP BY t.property ; 

Here is the solution. Result: enter image description here