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;