1.表数据结构如下
select * from test t insert into test values(1, 'jerry'); insert into test values(2, 'jerry'); insert into test values(3, 'jerry'); insert into test values(4, 'tom'); insert into test values(5, 'tom'); insert into test values(6, 'jake'); insert into test values(7, 'jake'); insert into test values(8, 'jake');
2.删除sql如下
a.name去重,取最小的字段
b.使用exists删除重复的数据
delete test a
where not exists
( select * from (select min(id) id, name from test group by name) b where a.id = b.id)