如何删除数据表中的重复数据(各种数据库)

来源:互联网 发布:c结构体转byte数组 编辑:程序博客网 时间:2024/06/05 20:49

oracle: delete  from test  a where  rowid>(select min(rowid) from test  b where a.name=b.name);


理解:记录虽然存在重复,但是rowid(物理地址)是唯一的,所以在子查询取得重复行中最小的rowid,删除重复行中
大于最小的rowid的行,只是保留了最小rowid的行,就是删除了重复行。

Mysql:

1、对于第一种重复,比较容易解决,使用

select distinct * from tableName

  就可以得到无重复记录的结果集。

  如果该表需要删除重复的记录(重复记录保留1条),可以按以下方法删除

select distinct * into #Tmp from tableName

drop table tableName

select * into tableName from #Tmp

drop table #Tmp
系列操作:查询,删除,插入,删除!~
原创粉丝点击