title: mySQL - performance of UNION statements
body: <p>I need to combine two tables with identical columns and use the result in complex JOIN queries, but it degrades the performance a lot. This query with UNIONs has an execution time of 7 sec:</p>
  
  <pre><code>SELECT DISTINCT `admin`.`Fund_ID`,
                  `admin`.`Fund_Name`
  FROM (
          (SELECT *
           FROM `admin`)
        UNION
          (SELECT *
           FROM `admin_custom`
           WHERE `user_id`=361)) admin
  LEFT JOIN (
               (SELECT *
                FROM `quant1`)
             UNION
               (SELECT *
                FROM `quant1_cust`
                WHERE `user_id`=361)) quant1 
  ON (quant1.`Fund ID`=`admin`.`Fund_ID`)
  WHERE quant1.`VaR 95`&gt;-0.028
  </code></pre>
  
  <p>But replacing a UNION clause by a simple table makes it only 0.006 sec. How can I fix the performance issues?</p>