title: MYSQL/PHP: Concat returning to many fields on LEFT JOIN
body: <p>I had a <code>SELECT</code> query with a <code>LEFT JOIN</code> working as desired.  I then added one more table via a smilar <code>LEFT JOIN</code> and now I am getting a wierd result.  Basically, for a <code>group_concat</code> where I was getting one item for every record, I am getting eight records.  I don't see why this is happening because the join to the new table is analagous to several other joins that do not have this problem (that I have omitted from the example for clarity).</p>
  
  <p>Here is the query that is fine:</p>
  
  <pre><code>$sql = "SELECT t.*, 
  group_concat(tf.todoid) as `tftodoid`, 
  group_concat(tf.id) as `tfid`, 
  group_concat(tf.filedescript) as `tffiledescript`, 
  group_concat(tf.filename) as `tffilename`, 
  group_concat(tf.founderid) as `tffounderid`, 
  group_concat(tf.ext) as `tfext`, 
  group_concat(tf.lasttouched) as `tilt`
  FROM titles `t`
  LEFT JOIN titlefiles `tf` 
  ON (tf.todoid = t.id AND tf.founderid = '$userid') 
  WHERE t.userid='$userid' 
  GROUP BY t.id";
  </code></pre>
  
  <p>And here is the query with the extra join that is now spilling out the multiple copies of the items:</p>
  
  <pre><code>$sql = "SELECT t.*, 
  group_concat(tf.todoid) as `tftodoid`, 
  group_concat(tf.id) as `tfid`, 
  group_concat(tf.filedescript) as `tffiledescript`, 
  group_concat(tf.filename) as `tffilename`, 
  group_concat(tf.founderid) as `tffounderid`, 
  group_concat(tf.ext) as `tfext`, 
  group_concat(tf.lasttouched) as `tilt`, 
  group_concat(s.id) as `stepid`, 
  group_concat(s.step) as `steps` 
  FROM titles `t`
  LEFT JOIN titlefiles `tf` 
  ON (tf.titleid = t.id AND tf.founderid = '$userid') 
  LEFT JOIN steps `s` 
  ON s.titleid = t.id 
  WHERE t.userid='$userid' 
  GROUP BY t.id";
  </code></pre>
  
  <p>Here is an example of output in JSON showing the difference:</p>
  
  <p>First query:</p>
  
  <pre><code>"tfid":"56,57,58,59,60,61,62,63,64,65,66,67,68,75,76,81"
  </code></pre>
  
  <p>Second query:</p>
  
  <pre><code>"tfid":"56,57,58,59,60,61,62,63,64,65,66,67,68,75,76,81,56,57,58,59,60,61,62,63,64,65,66,67,68,75,76,81,56,57,58,59,60,61,62,63,64,65,66,67,68,75,76,81,56,57,58,59,60,61,62,63,64,65,66,67,68,75,76,81,56,57,58,59,60,61,62,63,64,65,66,67,68,75,76,81,56,57,58,59,60,61,62,63,64,65,66,67,68,75,76,81,56,57,58,59,60,61,62,63,64,65,66,67,68,75,76,81,56,57,58,59,60,61,62,63,64,65,66,67,68,75,76,81,56,57,58,59,60,61,62,63,64,65,66,67,68,75,76,81",
  </code></pre>
  
  <p>I suspect the problem has something to do with the JOIN or with the Group By statements but I can't see how to fix. </p>
  
  <p>How can I ensure that I get only one fileid per file as opposed to eight?</p>