title: Duplicate Temporary Table MySQL
body: <p>I want to reference a temporary table multiple times in the same query. Due to the problem with temporary tables I cannot do that:</p>
  
  <p><a href="http://dev.mysql.com/doc/refman/5.7/en/temporary-table-problems.html" rel="noreferrer">http://dev.mysql.com/doc/refman/5.7/en/temporary-table-problems.html</a></p>
  
  <p>So to fix that I'm creating duplicates of the temporary table:</p>
  
  <pre><code>CREATE TEMPORARY TABLE IF NOT EXISTS earnings_temp_one AS (SELECT * FROM earnings WHERE earning_account_id = ?);
  CREATE TEMPORARY TABLE IF NOT EXISTS earnings_temp_two AS (SELECT * FROM earnings WHERE earning_account_id = ?);
  CREATE TEMPORARY TABLE IF NOT EXISTS earnings_temp_three AS (SELECT * FROM earnings WHERE earning_account_id = ?);
  </code></pre>
  
  <p>But this requires me to query the massive table earnings 3 times, which to some extent defeats the purpose.</p>
  
  <p><strong>Is there a way for me to duplicate a temporary table, under a different name?</strong></p>
  
  <p>Then I could run the query on the massive table just once.</p>
  
  <p>Or maybe there's a fix to the temporary table problem that doesn't require me to create duplicates?</p>