Reputation: 113
I want to copy records from one table to another table with extra columns.
The table columns looks like this
Table1: A,B,C,...,X
Table2: A,B,C,...,X,Y,Z
I know that i can do it in the following way
Insert into table2
Select
A,
B,
C,
...
X,
'1',
'1'
from table1
But it is a very inefficient way if the table contains lots of columns. I need to do the similar procedure for several tables. Is there a better way to do it?
I tried the following but it doesn't work
insert into table2 select * , '1', '1' from table1;
Upvotes: 1
Views: 3170
Reputation: 505
The thing you tried should work, just add alias.
INSERT INTO table2
SELECT t1.*,
'1',
'1'
FROM table1 t1;
Upvotes: 2
Reputation: 2175
Insert into table2 ( A, B, C, ... , X, Y , Z) SELECT ( A, B, C, ... , X, '1' , '1') from table1 ;
In this case Y & Z are Strings (characters).
Upvotes: 0