MySQL Inserting Multiple Columns and Rows into a Temporary Table
I have a temporary table:
CREATE TEMPORARY TABLE IF NOT EXISTS `temp`
AS (
SELECT COUNT(*) as count, YEAR(end_date)
FROM a
WHERE column_1 = "some_condition"
GROUP BY YEAR(end_date)
);
I then try to add on new values into this table
INSERT INTO temp (count, year)
VALUES(
SELECT COUNT(*) as count, year(end_date)
FROM b
WHERE column_1 = "some_condition"
GROUP BY YEAR(end_date)
);
And this line throws error.
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?
After the first query, temp table should look like this:
count year
3 2012
20 2013
104 2011
And the selected results from the second query looks like this
count year
6 2013
The expected outcome:
count year
3 2012
20 2013
104 2011
6 2013
No comments:
Post a Comment