title: How to merge MySQL queries with different column counts?
body: <p>Definitions: </p>
  
  <ul>
  <li>In the results, * denotes an empty column</li>
  <li>The data in the tables is such that every field in the table has the value Fieldname + RowCount (so column 'a' in row 1 contains the value 'a1').</li>
  </ul>
  
  <h3>2 MySQL Tables</h3>
  
  <ul>
  <li><p><strong>Table1</strong> 
  Fieldnames: a,b,c,d       </p></li>
  <li><p><strong>Table2</strong> 
  Fieldnames: e,f,g,h,i,j</p></li>
  </ul>
  
  <h3>Task:</h3>
  
  <p>I want to get the first 4 rows from each of the tables.</p>
  
  <p>Standalone Queries </p>
  
  <pre><code>SELECT Table1.* FROM Table1 WHERE 1 LIMIT 0,4 -- Colcount 4
  SELECT Table2.* FROM Table2 WHERE 1 LIMIT 0,4 -- Colcount 6
  </code></pre>
  
  <p>A simple UNION of the queries fails because the two parts have different column counts.</p>
  
  <h3>Version1: add two empty fields to the first query</h3>
  
  <pre><code>SELECT Table1.*,'' AS i,'' AS j FROM Table1 WHERE 1 LIMIT 0,4  
  UNION 
  SELECT Table2.* FROM Table2 WHERE 1 LIMIT 0,4
  </code></pre>
  
  <p>So I will get the following fields in the result set:</p>
  
  <pre><code>a,b,c,d,i,j
  
  a1,b1,c1,d1,*,*,
  a2,b2,c2,d2,*,*,
  ....
  ....
  e1,f1,g1,h1,i1,j1
  e2,f2,g2,h2,i2,j2
  </code></pre>
  
  <p>The problem is that the field names of Table2 are overridden by Table1.</p>
  
  <h3>Version2 - shift columns by using empty fields:</h3>
  
  <pre><code>  SELECT Table1.*,'','','','','','' FROM Table1 WHERE 1 LIMIT 0,4  
    UNION 
    SELECT '','','','',Table2.* FROM Table2 WHERE 1 LIMIT 0,4
  </code></pre>
  
  <p>So I will get the following fields in the result set:</p>
  
  <pre><code>a,b,c,d,i,j
  
  a1,b1,c1,d1,*,*,*,*,*,*,
  a2,b2,c2,d2,*,*,*,*,*,*,
  ....
  ....
  *,*,*,*,e1,f1,g1,h1,i1,j1
  *,*,*,*,e2,f2,g2,h2,i2,j2
  ....
  ....
  </code></pre>
  
  <p>Problem is solved but I get many empty fields. </p>
  
  <p>Is there a known performance issue?</p>
  
  <p>How do you solve this task? </p>
  
  <p>Is there a best practice to solve this issue? </p>