日期:2014-05-16  浏览次数:20768 次

Oracle如何删除重复数据
如题
表结构如下
员工标识 社会关系 姓名 年龄  
1 父子 a 22
1 父子 a 22
1 父子 a 22
2 母女 b 23
2 母女 b 23
3 父子 c 30
需要删除重复

1 父子 a 22
2 母女 b 23
3 父子 c 30


------解决方案--------------------
delete from table1 t1 where exists (select 1 from table1 t2 where t1.id = t2.id and t1.rowid > t2.rowid ) ;

试试看.
------解决方案--------------------
通过 rowid 来区分相同数据的记录行

SQL code
delete from table1
 where rowid not in (select max(rowid) from table1 group by 所有字段)

------解决方案--------------------
SQL code
delete from table1
 where rowid not in (select max(rowid) from table1 group by 所有字段)

------解决方案--------------------
2、3楼的正解,修改如下:
delete from 表名
 where rowid not in (select max(rowid) from 表名
 group by 员工标识,社会关系,姓名,年龄)
------解决方案--------------------
探讨
通过 rowid 来区分相同数据的记录行

SQL code
delete from table1
where rowid not in (select max(rowid) from table1 group by 所有字段)

------解决方案--------------------
delete from table1 a
where a.rowid<>(select max(rowid) from table1 b where a.主键=b.主键)

delete from table1
where rowid not in (select max(rowid) from table1 group by 所有字段)

学习了
------解决方案--------------------
探讨
通过 rowid 来区分相同数据的记录行


SQL code
delete from table1
where rowid not in (select max(rowid) from table1 group by 所有字段)

------解决方案--------------------
SQL code
delete from table1
 where rowid not in (select max(rowid) from table1 group by 所有字段)

------解决方案--------------------
探讨
SQL code

delete from table1
where rowid not in (select max(rowid) from table1 group by 所有字段)
正解

------解决方案--------------------
rowid速度最优