title: Aliasing derived table which is a union of two selects
body: <p>I can't get the syntax right for aliasing the derived table correctly:</p>
  
  <pre><code>SELECT * FROM 
    (SELECT a.*, b.* 
      FROM a INNER JOIN b ON a.B_id = b.B_id
      WHERE a.flag IS NULL AND b.date &lt; NOW()
    UNION
    SELECT a.*, b.* 
      FROM a INNER JOIN b ON a.B_id = b.B_id
      INNER JOIN c ON a.C_id = c.C_id
      WHERE a.flag IS NOT NULL AND c.date &lt; NOW())
    AS t1
  ORDER BY RAND() LIMIT 1
  </code></pre>
  
  <p>I'm getting a Duplicate column name of B_id. Any suggestions?</p>