Skip to content
Advertisement

MySQl Query: copy a column named ‘C’ from table2 to column ‘C’ in table1 without losing any other column data

I have 2 tables table1 and table2. I have to copy a column named ‘C’ from table2 to column ‘C’ in table1 without losing any other column data. Both field data types are same. Can anybody give me a proper query how to do it.

Advertisement

Answer

Assuming the Table1 already contains the C column and you can Join by id:

UPDATE table1 t1 JOIN table2 t2 ON t1.id = t2.id
SET t1.col1 = t2.col2, t1.col2 = t2.col2

source: http://blog.ookamikun.com/2008/03/mysql-update-with-join.html

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement