title: MySQL Inserting Multiple Columns and Rows into a Temporary Table
body: <p>I have a temporary table:</p>
  <pre><code>CREATE TEMPORARY TABLE IF NOT EXISTS `temp`
  AS (
   SELECT COUNT(*) as count, YEAR(end_date)
   FROM a
   WHERE column_1 = &quot;some_condition&quot;
   GROUP BY YEAR(end_date)
  );
  </code></pre>
  <p>I then try to add on new values into this table</p>
  <pre><code>INSERT INTO temp (count, year)
  VALUES(
    SELECT COUNT(*) as count, year(end_date)
    FROM b
    WHERE column_1 = &quot;some_condition&quot;
    GROUP BY YEAR(end_date)
  );
  </code></pre>
  <p>And this line throws error.
  Error given:</p>
  <blockquote>
  <h1>1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use</h1>
  <p>near 'SELECT COUNT(*) as count, year(end_date)   FROM b<br />
  WHERE column_1 = &quot;some condition&quot; ' at line 3</p>
  </blockquote>
  <p>What I'm trying to achieve is for the new rows and columns which were selected to be inserted into the temporary table. Any ideas?</p>
  <p>After the first query, temp table should look like this:</p>
  <pre><code>count  year
  3      2012
  20     2013
  104    2011
  </code></pre>
  <p>And the selected results from the second query looks like this</p>
  <pre><code>count  year
  6      2013
  </code></pre>
  <p>The expected outcome:</p>
  <pre><code>count  year
  3      2012
  20     2013
  104    2011
  6      2013
  </code></pre>