title: Getting max value from many tables
body: <p>There are two ways, that I can think of, to obtain similar results from multiple tables. One is <code>UNION</code> and the other is <code>JOIN</code>. The similar questions on SO have all been answered with a <code>UNION</code>. Here's the coder I just found:</p>
  
  <pre><code>SELECT max(up.id) AS up, max(sc.id) AS sc, max(cl.id) AS cl
      FROM updates up, chat_staff sc, change_log cl
  </code></pre>
  
  <p>explain:</p>
  
  <pre><code>+----+-------------+-------+------+---------------+------+---------+------+------+------------------------------+
  | id | select_type | table | type | possible_keys | key  | key_len | ref  | rows | Extra                        |
  +----+-------------+-------+------+---------------+------+---------+------+------+------------------------------+
  |  1 | SIMPLE      | NULL  | NULL | NULL          | NULL | NULL    | NULL | NULL | Select tables optimized away |
  +----+-------------+-------+------+---------------+------+---------+------+------+------------------------------+
  </code></pre>
  
  <p>My question is -- Is this better than the following?</p>
  
  <pre><code>SELECT "up.id" AS K, max(id) AS V FROM updates 
   UNION
  SELECT "sc.id" AS K, max(id) AS V FROM chat_staff 
   UNION
  SELECT "cl.id" AS K, max(id) AS V FROM change_log
  </code></pre>
  
  <p>explain:</p>
  
  <pre><code>+----+--------------+--------------+------+---------------+------+---------+------+-------------------------------------+
  | id | select_type  | table        | type | possible_keys | key  | key_len | ref  | rows | Extra                        |
  +----+--------------+--------------+------+---------------+------+---------+------+------+------------------------------+
  |  1 | PRIMARY      | NULL         | NULL | NULL          | NULL | NULL    | NULL | NULL | Select tables optimized away |
  |  2 | UNION        | NULL         | NULL | NULL          | NULL | NULL    | NULL | NULL | Select tables optimized away |
  |  3 | UNION        | NULL         | NULL | NULL          | NULL | NULL    | NULL | NULL | Select tables optimized away |
  | NULL | UNION RESULT | &lt;union1,2,3&gt; | ALL  | NULL          | NULL | NULL    | NULL | NULL |                              |
  +----+--------------+--------------+------+---------------+------+---------+------+------+------------------------------+
  </code></pre>