create table 临时表 as
select a.字段1,a.字段2,MAX(a.ROWID) dataid from 正式表 a GROUP BY a.字段1,a.字段2;
delete from 表名 a
where a.rowid !=
(
select b.dataid from 临时表 b
where a.字段1 = b.字段1 and
a.字段2 = b.字段2
);
commit;
二、完全删除重复记录
对于表中两行记录完全一样的情况,可以用下面语句获取到去掉重复数据后的记录:
select distinct * from 表名
可以将查询的记录放到临时表中,然后再将原来的表记录删除,最后将临时表的数据导回原来的表中。如下:
CREATE TABLE 临时表 AS (select distinct * from 表名);
truncate table 正式表; --注:原先由于笔误写成了drop table 正式表;,现在已经改正过来
insert into 正式表 (select * from 临时表);
drop table 临时表;