简体   繁体   中英

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM