2017-05-28

MySQL - GROUP_CONCAT function to list one-to-many relationships as comma-separated values

SELECT
m.SectionId
, GROUP_CONCAT( d.TranslationId ) AS TranslationIds
FROM
  TABLE_1_HERE AS m
  INNER JOIN TABLE_2_HERE AS d
  ON m.SectionId = d.SectionId
GROUP BY
  m.SectionId
;

PS. In this example, a section can have multiple translations. The result will be that, for each section row, multiple translation values will be calculated inside a single field.

No comments:

Post a Comment