You can't specify target table 'a' for update in FROM clause
表a 的id字段不做唯一约束,表中aa,bb字段数据重复,目前希望aa,bb字段组合确定唯一一条数据,如何删除表a中的重复数据,保留id值最小的哪一条数据。
执行sql:
delete from a where id not in (select MIN(id) as id from a GROUP BY aa,bb)
错误:You can't specify target table 'a' for update in FROM clause
含义:不能在同一表中查询的数据作为同一表的更新数据。
正确写法:delete from a where id not in (select * from (select MIN(id) as id from a GROUP BY aa,bb) as f)
查看数据:
数据被删除