I have a two tables A and B
I would like to union them and store in to another table;
CREATE TABLE myspace.test (
(select * from A ) UNION ( select * from B) );
It fails with an error
You have an error in your SQL syntax;
check the manual that corresponds to
your MySQL server version for the
right syntax to use near ‘CREATE TABLE
myspace.test ( (select * from A )
UNION ( s’ at line 1
But the query with: (select * from A ) UNION ( select * from B) gives correct result.
How to store union result in to another table??
Thanks Arman.
EDIT
Well After playing around I found that:
-
The query without outer brackets works.
CREATE TABLE myspace.test
(select * from A ) UNION ( select * from B) ; -
Adding AS is not solving the problem.
-
I was wondered that query with brackets is working well seems tome BUG or maybe I am missing something?
CREATE TABLE myspace.test
(select * from A);
Read the documentation. There are no parens around the
select-statement.Watch out for duplicate primary keys, though. You may want to consider first creating an empty table
myspace.testwith the proper layout, then inserting rows into it more selectively.