1.sql删除重复其他项
tb:
删除其中name有重复的记录中id较小的记录(只保留id最大的一条),如上图最终结果:
id name
3 a
5 b
6 c
正确的一条SQL语句如下:
delete from tb where id not in(select id from (select name,max(id) as id from tb group by name) t);
注:delete from tb where id in(select id from tb)报错:You can't specify target table 'tb' for update in FROM clause。
2.sql取重复里面最新的记录