mysql中You can’t specify target table for update in FROM clause毛病處理辦法。本站提示廣大學習愛好者:(mysql中You can’t specify target table for update in FROM clause毛病處理辦法)文章只能為提供參考,不一定能成為您想要的結果。以下是mysql中You can’t specify target table for update in FROM clause毛病處理辦法正文
mysql中You can't specify target table for update in FROM clause毛病的意思是說,不克不及先select出統一表中的某些值,再update這個表(在統一語句中)。 例以下面這個sql:
delete from tbl where id in
(
select max(id) from tbl a where EXISTS
(
select 1 from tbl b where a.tac=b.tac group by tac HAVING count(1)>1
)
group by tac
)
改寫成上面就好了:
delete from tbl where id in
(
select a.id from
(
select max(id) id from tbl a where EXISTS
(
select 1 from tbl b where a.tac=b.tac group by tac HAVING count(1)>1
)
group by tac
) a
)
也就是說將select出的成果再經由過程中央表select一遍,如許就躲避了毛病。留意,這個成績只湧現於mysql,mssql和oracle不會湧現此成績。