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);

速度有很大的提升

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM