title: Combining records from two Mysql tables
body: <p>I have two tables:</p>
  
  <p><em>records</em></p>
  
  <pre><code>id  subrecord_of
  1   0
  2   1
  3   0
  4   1
  5   0
  6   5
  </code></pre>
  
  <p><em>values</em></p>
  
  <pre><code>   id   value
      1   11
      1   111
      2   222
      2   222
      2   2222
      3   33
      4   44
      6   66
      6   666
  </code></pre>
  
  <p>The goal is to select records not being subrecords</p>
  
  <p>with corresponding sum of values from records and subrecords:</p>
  
  <pre><code>id  sub    sum_of_values
  1   2,4     11,111,2222,222,44
  3   null    33
  5   6       666,66
  </code></pre>
  
  <p>column "id"  - records where sub is 0</p>
  
  <p>column "sub" - list of subrecords
  fe id 2 and id 4 are subrecords of id 1</p>
  
  <p>column "values" - list of unique values
  fe id 1 = distinct values from id1 + id2 + id4</p>
  
  <p>Any help?</p>