RSS
热门关键字:  下载  cms  模版  开源  dedecms
当前位置 :| 主页 > 站长学院 > 数据库 > Oracle >

在Oracle中找出重复的纪录的方法

来源:Blog.ChinaUnix.net 作者:未知 时间:2006-09-14 Tag: 点击:

SQL> desc test
 Name                                      Null?    Type
 ----------------------------------------- -------- -----------------
 ID                                                 NUMBER
--表 test有重复的记录1,10
SQL> select * from test;

        ID
----------
         1
         2
         3
         4
        10
         1
         1
         1
         1
         1
        10

11 rows selected.
--查询表中的哪些记录有重复

SQL> select * from test group by id having count(*)>1;

        ID
----------
         1
        10
--查询出没有重复记录的结果集
SQL> select * from test group by id;

        ID
----------
         1
         2
         3
         4
        10

SQL> select distinct * from test;

        ID
----------
         1
         2
         3
         4
        10
--删除重复的记录
SQL> delete from test a where a.rowid!=(select max(rowid) from test b
  2  where a.id=b.id);

6 rows deleted.

SQL> commit;

Commit complete.
--删除后的查询结果集
SQL> select * from test;

        ID
----------
         2
         3
         4
         1
        10


最新评论共有 0 位网友发表了评论
发表评论
评论内容:不能超过250字,需审核,请自觉遵守互联网相关政策法规。
用户名: 密码:
匿名?
注册
栏目列表