MySQL:You can't specify target table for update in FROM clause
阿新 • • 發佈:2018-11-24
問題:You can't specify target table for update in FROM clause
含義:不能在同一表中查詢的資料作為同一表的更新資料。
注意:這個問題只出現於mysql,mssql和oracle不會出現此問題。
delete from people where peopleid in (select peopleid from people group by peopleid having count(peopleid)>1) and rowid not in (select MIN(rowid) from people group by peopleid having count(peopleid)>1)
修改後程式碼:
delete from people where peopleId in (SELECT a.peopleid FROM (select peopleId from people group by peopleId having count(peopleId) > 1) a) and rowid not in (SELECT b.rowid FROM (select MIN(rowid) rowid from people group by peopleId having count(peopleId )>1) b)
查詢資料結果集中再套一層
PS:感謝Cap_ZZ https://blog.csdn.net/qq_38481999/article/details/80916034#commentBox