错误:You can't specify target table 'xxx' for update in FROM clause的解决
in 随笔 with 0 comment

错误:You can't specify target table 'xxx' for update in FROM clause的解决

in 随笔 with 0 comment

select 和update 不能同时使用
解决方案
查询的时候增加一层中间表,就可以避免该错误。


delete from t where pid in (
    select temp.pid from (
        select pid from t 
            group by pid HAVING count(1)>1
    ) temp
)

为什么这么修改?这里再查一次,然后重命名为temp,这样MySQL就检查不到是同一张表。

Responses