title: Mysql multiple matches with left join
body: <p>Hello i working with multiple tables(around 40) and i make a left Join for link multiple tables, the problem is in some of those tables there are multiple matches and for this rason get many rows, them i look a method for get the result more organized, because this result is sended to Javascript and the result is many tables, and many columns with <code>null</code> value .</p>
  
  <pre><code>MainTbl
      +-------------------+
      | id  columA columB |
      +-------------------+
      | 1    data   data  |
      | 2    data   data  |
      | 3    data   data  |
      | 4    data   data  |
      +-------------------+
  
       Table1
      +-------------------+
      | id  columA columB |
      +-------------------+
      | 1    data   data  |
      | 1    data   data  |
      | 1    data   data  |
      | 2    data   data  |
      +-------------------+
   Table2
      +-------------------+
      | id  columA columB |
      +-------------------+
      | 2    data   data  |
      | 2    data   data  |
      | 1    data   data  |
      | 1    data   data  |
      +-------------------+
  </code></pre>
  
  <p>and i make a left join like this:</p>
  
  <pre><code>SELECT blah,blah,blah
  FROM MainTbl
  LEFT JOIN  Table1 ON  Table1.Id = MainTbl.Id
  LEFT JOIN  Table2 ON  Table2.Id = MainTbl.Id
  ...
  ...
  ..
  LEFT JOIN  Table40 ON  Table40.Id = MainTbl.Id
  </code></pre>
  
  <p><strong>Other option</strong> i see is make a select for each ID, and organize it by table, example
  <code>select * from table1 where id='1'</code>, this result i can concat with <code>table2,table3...table40</code>, after concat subtables i can concat with main table, the result can be like this.</p>
  
  <pre><code>Maintbl[
          MainA:'data',
          MainA:'data',
          Table1:[
                  items:[
                          subT1:[
                                Sub_subT1:data,
                                Sub_subT1:data
                                 ],
                          subT1:[
                                Sub_subT1:data,
                                Sub_subT1:data
                                 ],
                          subT1:[
                                Sub_subT1:data,
                                Sub_subT1:data
                                 ]
                          ]
                   ],
            Table2:[
                  items:[
                          subT2:[
                                Sub_subT2:data,
                                Sub_subT2:data
                                 ],
                          subT2:[
                                Sub_subT2:data,
                                Sub_subT2:data
                                 ],
                          subT2:[
                                Sub_subT2:data,
                                Sub_subT2:data
                                 ]
                          ]
                   ]   
  
  ]
  </code></pre>
  
  <p>but I see a problem "resource consumption", because i need to work with 40 tables, and that is 40 selects, i dont know if this method is better o not, but i no see other solution for this problem.</p>