1.通過創建臨時表
creat table tbl_tmp as select distinct * from tbl;
truncate table tbl;//清空表記錄
insert into tbl select * from tbl_tmp;//將臨時表中的數據插回來。
2.利用rowid
delete from tbl where rowid in
(select a.rowid from tbl a, tbl b
where a.rowid>b.rowid
and a.col1=b.col1 and a.col2 = b.col2)
3.利用max或min函數
delete from tbl a where rowid not in
(select max(b.rowid) from tbl b where a.col1=b.col1 and a.col2 = b.col2);
//這里max使用min也可以
delete from tbl where rowid not in
(select max(rowid) from tbl tgroup by t.col1, t.col2);