原文:https://www.cnblogs.com/dearroy/p/14133444.html

有两张表,info1, info2 。

info1:

info2:

现在,要用info2中的数据更新info1中对应的学生信息,sql语句如下:

UPDATE info1 t1 JOIN info2 t2 
ON t1.name = t2.name
SET t1.age = t2.age, t1.class = t2.class;

运行结果如下:

更新过的info1:

至于效率问题,之前我有三张表,都在40万左右。需要将 table2 中的两个字段(step1),table3 中的一个字段(step2),更新到 table1 中。step1 用时半个小时左右,而 step2 用了两个多小时,不知为何。三个表都根据一个相同字段建立了唯一索引。