MYSQL错误:You can't specify target table for update in FROM clause

这句话意思是:不能先select再更新(修改)同一个表。

可以再外嵌套多一层,这个问题只有mysql有,mssql和oracle都没有。

# 出错
delete
from Person where Id not in (   select min(Id) as Id from Person group by Email);

 

# 正确
delete
from Person where Id not in (   select Id from (     select min(Id) as Id from Person group by Email) p);

 

posted on 2018-01-31 10:42  willaty  阅读(212)  评论(0编辑  收藏  举报

导航