Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Team,
I am trying to copy data from one table to another with an additional value.

FROM table1 I need to copy two column values such as ERNO and ENAME to table2.
Also need to update or add ECNO.

Note: I am using MySQL.
Not only one field ECNO, also need to add more field while copying data from one table to another.

What I have tried:

Follwing query I have used for that. But  it doesn't work

<pre>INSERT INTO TABLE2 (ECNO, ERNO, ENAME) values (1, select ERNO, ENAME from TABLE1)
Posted
Updated 12-Feb-18 19:51pm

Use query as below
INSERT INTO TABLE2 (ECNO, ERNO, ENAME)
Select 1, ERNO, ENAME from TABLE1

You can add where clause for add condition if you want to insert specific data only from Table1
 
Share this answer
 
v3
If you would like to insert data into another table, use: MySQL :: MySQL 5.7 Reference Manual :: 13.2.5.1 INSERT ... SELECT Syntax[^]
If you would like to update, see: MySQL :: MySQL 5.7 Reference Manual :: 13.2.11 UPDATE Syntax[^]
For update + select, see: MySQL - UPDATE query based on SELECT Query - Stack Overflow[^]
Good luck!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900