mysql 用一个表去更新另一个表

表1

表2

通过两个表的auid 相同,来更新表2 中的F1,如果直接用:

update table2 t2 ,table1 t1 set t2.f1=1 where t2.auid = t1.auid 

在mysql 中执行报错为死锁

为解决此问题:
改为:

 update table2 t2 set t2.f1=1 where t2.auid in (select distinct auid from table1)

但是这样 速度还是太慢

改为:

update com_tab_copy set f1 = 1 where auid in (select auid from (select distinct auid from ar_copy)as t1);

速度有很大的提升

 

posted @ 2019-04-28 09:53  秀秀的土拨鼠  阅读(1295)  评论(0编辑  收藏  举报