title: Mysql join get multiple rows at right
body: <p>I have two tables:</p>
  
  <pre><code># products (id,name,value,time)
  
  # product_data (id,product_id,field_name,field_value)
  (1,1,color,red)
  (2,1,size,big)
  (3,1,whatever,value)
  </code></pre>
  
  <p>I want to make a query that takes field values from products table and also adds all product_data rows that have the same product id, like this:</p>
  
  <pre><code>$row = array(
    id =&gt; 1,
    name =&gt; Gloves,
    value =&gt; 15,
    color =&gt; red,
    size =&gt; big,
    ...
  ) 
  </code></pre>
  
  <p>Maybe its not very good way to store all that data and I should store all fields in one table but since there will be a lot of different product types there always would be a lot of empty fields. The queries would be a lot simpler like that because I would have to be able to sort products by color for example (by values from <code>products_data</code>).</p>
  
  <p>I have tried this for example but this only lists field names, not values:</p>
  
  <pre><code>SELECT *,
         group_concat(product_data.fname) AS afield
  FROM product_data
  LEFT JOIN products ON products.id = product_data.pid
  </code></pre>