You can't specify target 'table' for update in FROM clausemysql
個人sql語句是這樣的(簡化版):sql
update A
code
set type= 0
cdn
where id in
blog
(select a.id from A a,B b where a.bId= b.id and b.mId=#{mId} and a.tel=#{tel});
ci
在作更新操做的時候,又作了一次表內查詢,這顯然會致使必要的字段被隱式複製到臨時表中。get
解決方案it
多作一次A表的查詢,爲了讓A的臨時表不衝突,將sql語句改動一下:io
update A
table
set type= 0
where id in
(select a.id from (select id,bId,tel from A) a,B b where a.bId= b.id and b.mId=#{mId} and a.tel=#{tel});
ps:這個新的查詢語句,只將表A中的幾個字段查出來做爲臨時表,而不是整個表A做爲臨時表
從新執行:
問題解決
您的點贊和關注是對我最大的支持,謝謝!