title: MySQL group certain results into an array
body: <p>I'm writing a complex MySQL query with multiple <code>LEFT JOIN</code>s to combine data from several different tables.</p>
  
  <pre><code>$public_query = 
  "SELECT * FROM  `wsat_ib` 
  LEFT JOIN wp_usermeta ON wsat_ib.user_id = wp_usermeta.user_id
  LEFT JOIN wpjb_resume ON wsat_ib.user_id = wpjb_resume.user_id
  LEFT JOIN wpjb_field_value ON wpjb_resume.id=wpjb_field_value.job_id 
  LEFT JOIN wpjb_application ON wpjb_application.user_id = wsat_ib.user_id
  WHERE wp_usermeta.meta_key =  'target_employer'
  AND wp_usermeta.meta_value =  'public'
  AND wpjb_resume.is_active =1
  ";
  </code></pre>
  
  <p><strong>My problem</strong>: The table wp_usermeta can have multiple rows for the same user_id. For example a user (with user_id = 5) may have more then one row in the table wp_usermeta with the field: meta_key that is 'target_employer'. In case that's not clear, the rows might look like this.</p>
  
  <pre><code>id    user_id    meta_key           meta_value
  1     5          target_employer    13
  2     5          target_employer    53
  3     79         target_employer    21
  </code></pre>
  
  <p><strong>My Question</strong>: Is there any way that I can return each matching row from wp_usermeta as an array in one of my result objects? So the <code>var_dump()</code> would look something like this:</p>
  
  <pre><code>object(stdClass)#2906 (14) {
    ["user_id"]=&gt;
    string(4) "5"
    ["firstname"]=&gt;
    string(6) "Bilbo"
    ["lastname"]=&gt;
    string(3) "Baggins"
    ...
    ["target_employer"]=&gt;
    array(2) {
      [0]=&gt;13,
      [1]=&gt;53
    }
  }
  </code></pre>
  
  <p>UPDATE:
  @bpanulla: Here's the real (unsimplified query)...</p>
  
  <pre><code>"SELECT wsat_ib.user_id, wpjb_resume.firstname, wpjb_resume.lastname, wsat_ib.overall_score, wsat_ib.account_score, wsat_ib.econ_score, wsat_ib.math_score, wsat_ib.logic_score, wsat_ib.fsanaly_score, wsat_ib.corpval_score, wsat_ib.end_time, GROUP_CONCAT(wp_usermeta.meta_value) AS target_employers, wpjb_field_value.value AS school, wpjb_application.job_id
  FROM  `wsat_ib` 
  LEFT JOIN wp_usermeta ON wsat_ib.user_id = wp_usermeta.user_id
  LEFT JOIN wpjb_resume ON wsat_ib.user_id = wpjb_resume.user_id
  LEFT JOIN wpjb_field_value ON wpjb_resume.id=wpjb_field_value.job_id 
  LEFT JOIN wpjb_application ON wpjb_application.user_id = wsat_ib.user_id AND wpjb_application.field_id=3
  WHERE (wp_usermeta.meta_key =  'target_employer'
  AND wp_usermeta.meta_value =  'public'
  AND wpjb_resume.is_active =1)
  GROUP BY user_id
  ";
  </code></pre>