一,去除多余的重复记录,以下以判断a字段,如果字段相同则记录相同
1、使用 rowid的方式
①正常版
delete from stu
where
a in (select a from stu group by a having count(a)>1)
and
rowid not in (select min(rowid) from people group by a having count(a)>1);
② 简便版
delete from stu
where rowid not in (select min(rowid) from stu group by a);
③ 使用表连接和 rowid 的方式
delete from stu t1
where rowid not in (select min(rowid) from stu t2 where t1.a=t2.a);
二,以多个字段判定记录相同,原理相同(如 a,b 字段)
delete from stu
where
stu.a,stu.b in (select a,b from stu group by a,b having count(*)>1)
and
rowid not in (select min(rowid) from people group by a,b having count(a)>1);
delete from stu
where rowid not in (select min(rowid) from stu group by a,b);