Mysql
 sql >> Datenbank >  >> RDS >> Mysql

MySql duplizierte Werte in einem Join mit GROUP_CONCAT

Also antworte ich mir. Was ich gesucht habe, ist CONCAT_WS . Meine Bitte wird dann

SELECT t1.*,
       GROUP_CONCAT(DISTINCT CONCAT_WS(
            ' ', t2.info, t2.data
       ) SEPARATOR  ', ') AS info,
       GROUP_CONCAT(DISTINCT t3.email SEPARATOR '|') AS email
FROM table1 AS t1
LEFT JOIN link1 AS l1
ON l1.id_a = t1.id_a
LEFT JOIN table2 AS t2
ON t2.id_b = l1.id_b
LEFT JOIN link2 AS l2
ON l2.id_a = t1.id_a
LEFT JOIN table3 AS t3
ON t3.id_c = l2.id_c
WHERE t1.id_a = ?
GROUP BY t1.id_a