title: MySQL performance – Multiple queries or one inefficient query?
body: <p>I have three tables, each contain some common information, and some information that is unique to the table.
  For example: <code>uid</code>, <code>date</code> are universal among the tables, but one table can contain a column <code>type</code> while the other contains <code>currency</code>.
  I need to query the database and get the last 20 entries (<code>date DESC</code>) that have been entered in all three tables.
  My options are:</p>
  
  <ol>
  <li><p>Query the database once, with one large query, containing three <code>UNION ALL</code> clauses, and pass along fake values for columns, IE:</p>
  
  <pre><code>FROM    (
      SELECT  uid, date, currency, 0, 0, 0
  </code></pre>
  
  <p>and later on</p>
  
  <pre><code>FROM    (
      SELECT  uid, date, 0, type, 0, 0
  </code></pre>
  
  <p>This would leave me with allot of null-valued fields..</p></li>
  <li><p>OR I can query  the database three times, and somehow within PHP <code>sort</code> through the information to get the combined latest 20 posts. This would leave me with an excess of information - 60 posts to look through (<code>LIMIT 20</code>) * 3 - and force me to preform some type of addtional quicksort every time.</p></li>
  </ol>
  
  <p>What option is better/any alternate ideas?</p>
  
  <p>Thanks.</p>