I betragtning af dine data burde denne forespørgsel returnere det, du ønsker:
SELECT t1.*,
GROUP_CONCAT(t2.info SEPARATOR '|') AS info,
GROUP_CONCAT(t2.data SEPARATOR '|') AS data
FROM table1 t1 LEFT JOIN
join j
ON j.id_a = t1.id_a LEFT JOIN
table2 t2
ON t2.id_b = j.id_b
WHERE t1.id_a = ?
GROUP BY t1.id_a;
Hvis du vil, kan du fjerne dubletterne ved at bruge DISTINCT
:
SELECT t1.*,
GROUP_CONCAT(DISTINCT t2.info SEPARATOR '|') AS info,
GROUP_CONCAT(DISTINCT t2.data SEPARATOR '|') AS data
FROM table1 t1 LEFT JOIN
join j
ON j.id_a = t1.id_a LEFT JOIN
table2 t2
ON t2.id_b = j.id_b
WHERE t1.id_a = ?
GROUP BY t1.id_a;
Typisk er det dog bedre at rette forespørgslen, så den ikke genererer dubletterne.