title: MySQL query - single row in one table with multiple rows in another table
body: <p>I have the following data model</p>
  
  <pre><code>Table: User
  USER ID
  USER NAME
  
  Table: Group
  GROUP ID
  GROUP NAME
  
  Table: User Group
  GROUP ID
  USER ID
  </code></pre>
  
  <p>I am trying to display a screen with all group names and associated users - the front end is PHP</p>
  
  <p>The query I have is as below - </p>
  
  <pre><code>`SELECT a.group_id,
          a.group_name,
          GROUP_CONCAT(g.user_id) AS user_ids,
          GROUP_CONCAT(u.user_fname) AS user_names
   FROM   group a, user_group g, user u
   WHERE  a.group_id = g.group_id
   AND    g.user_id = u.user_id
   GROUP BY a.group_id`
  </code></pre>
  
  <p>My question : As you can see from the above query - I have to have two lists of concatenated strings that represent user ids and user names. This becomes a headache in PHP as I have to 
  1. Explode both concatenated strings into arrays
  2. Run a loop through both arrays and construct User objects from them
  3. Then pass the array of objects over</p>
  
  <p>Is there a more efficient / better way to do this? Any suggestions, pointers would be appreciated.</p>