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