1.只保留重复行的一条数据,其余删除。
delete from 表1 a
where a.rowid !=(select max(rowid)
from 表1 b
where b.字段1=a.字段1 and b.字段2=a.字段2)
注:字段1或字段2中不能含有空值,如果为空,空值所在的行相同的值就不能删除
2.创建一个临时表
create table 临时表 as
(select max(主键) ,字段1,字段2
from 表 group by 字段1,字段2)
清空主表
truncate table 主表
插入数据
insert into 主表(select * from 临时表);
commit;