title: Duplicate values in GROUP_CONCAT when using two many-to-many
body: <p>I'm trying to get in a string two many-to-many associations. In this example, each team has an undetermined number of colours and an undetermined number won awards.</p>
  
  <p>This is the schema:</p>
  
  <p><img src="https://i.stack.imgur.com/jqCk4.png" alt="enter image description here"></p>
  
  <p>And this is the query I'm using:</p>
  
  <pre><code>SELECT
      teams.name AS name,
      GROUP_CONCAT(colours.name) AS colours,
      GROUP_CONCAT(awards.name) AS awards
  FROM
      teams
  
  -- join colours
  INNER JOIN teams_to_colours
          ON teams.id = teams_to_colours.team_id
  
  INNER JOIN colours
          ON teams_to_colours.colour_id = colours.id
  
  -- join awards
  INNER JOIN teams_to_awards
          ON teams.id = teams_to_awards.team_id
  
  INNER JOIN awards
          ON teams_to_awards.award_id = awards.id
  
  WHERE
      teams.name="A-Team"
  
  GROUP BY
      teams.id
  </code></pre>
  
  <p><strong>The problem is that the colours and the awards get duplicated</strong>. Let's say A-Team has red and blue as colours, and as awards TrollAward and DarwinAward... the results I get from the SQL look like this:</p>
  
  <pre><code>name: "A-Team"
  colours: "red,blue,red,blue"
  awards: "TrollAward,DarwinAward,TrollAward,DarwinAward"
  </code></pre>
  
  <p>I have tried to join only one many-to-many, and works perfectly, so I guess I'm overseeing something with the multiple joins...</p>