Reputation: 95
I am trying to copy data from one table to another with an additional value.
from table1 I need to copy two column(field) values such as ERNO and ENAME to table2. Also need to update or add ECNO(column or field).
Note: I am using MySQL. Not only one field ECNO, also need to add more field while copying data from one table to another. ECNO field is int datatype.
Follwing query I have used for that. But it doesn't work
INSERT INTO TABLE2 (ECNO, ERNO, ENAME) values (1, select ERNO, ENAME from TABLE1) Any Suggestion how to do this in proper way.
Upvotes: 0
Views: 96
Reputation: 4739
Use like this:
INSERT INTO tbl2 (col1, col2.....)
SELECT tbl1.col1,tbl1.col2
FROM tbl
Upvotes: 1
Reputation: 263693
Use INSERT INTO...SELECT syntax:
INSERT INTO TABLE2 (ECNO, ERNO, ENAME)
SELECT 1, ERNO, ENAME
FROM TABLE1
Upvotes: 2