MySQL 两张表关联更新(用一个表的数据更新另一个表的数据)

有两张表,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 用了两个多小时,不知为何。三个表都根据一个相同字段建立了唯一索引。

本人装了 navicat 破解版,垃圾,有时候越着急,就越是卡。

猜你喜欢

转载自www.cnblogs.com/zrmw/p/11720684.html