一,去除多餘的重複記錄,以下以判斷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);