简体   繁体   English

MySQL-将数据从行复制到另一个表?

[英]MySQL - copy data from row to another table?

I have a table1 and table2 I want to update the address in table2 according to the name in table1 我有一个table1和table2我想根据table1中的名称更新table2中的地址

for example : 例如 :

table 1 (the curent update data) 表1(当前更新数据)

jhonny 1st street david 2nd street danny 4th street 约翰尼第一街大卫第二街丹尼第四街

table 2 (old): 表2(旧):

jhonny unknown 约翰尼未知

david 5th street 大卫第五街

danny france 丹尼·法兰西

daniel 2nd street 丹尼尔第二街

table2 (need to be as table1) table2(必须与table1相同)

jhonny 1st street 约翰尼第一街

david 2nd street 大卫第二街

danny 4th street 丹尼第四街

daniel 2nd street 丹尼尔第二街

is there a command that do it automateclly ? 有自动执行的命令吗? or I need to write a code for it? 还是我需要为此编写代码?

Thanks , 谢谢 ,

Try this: 尝试这个:

UPDATE Table1, Table2
SET Table2.address = Table1.address
WHERE Table1.Name = Table2.Name

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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