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);
【本文章出自博客园willaty,转载请注明作者出处,误差欢迎指出~】