I would like to know how MySQL interprets the CREATE TABLE syntax:
If I write:
CREATE TABLE tbl1 (
`v1` int,
`v2` int
CONSTRAINT idx PRIMARY KEY (v1)
)
SELECT a, b FROM tbl2;
-
Does it determine which value goes into
v1and which goes intov2
by their order in the select statement? -
Does it use the names I designate in the
CREATE TABLEstatement or
does it take them from the select statement?
I have used the CREATE TABLE XX SELECT val FROM YY before but would like to know more specifically about the above syntax.
With your current solution you’ll get a table with the columns
v1,v2,a, andb.To see how it is done properly, see the "CREATE TABLE … SELECT Statement" chapter in the official MySQL documentation.
So if you just want
v1andv2with an index onv1, do it like this: