create table test1(
id number,
name varchar2(20)
);

  

insert into test1 values(1,'jack');
insert into test1 values(2,'jack');
insert into test1 values(3,'peter');
insert into test1 values(4,'red');

 insert into test1 values(5,'green');
  insert into test1 values(6,'green');

一 查询表中重复数据

1. 使用exists

 select a.* from test1 a

 where exists

 (
select name from
( select name ,count(*)
from test1
group by name
having count(*)>1
) b
where a.name = b.name
);

2 join on

select a. * from test1 a
join (
select name ,count(*) from test1
group by name
having count(*)>1
) b
on a.name = b.name;

3 in

select a.name from test1 a
where a.name in
(
select name from test1
group by name
having count(*)>1
);

4 使用rowid 查询得到重复记录里,第一条插入记录后面的记录

select * from test1 a where  rowid != (select min(rowid) from test1 b where b.name = a.name);

  

5 使用rowid查询得到重复记录里,最后一条记录之前插入的记录

select a.* from test1 a where rowid !=(select max(rowid) from test1 b where a.name=b.name);

  

6 使用rowid 查询得到 不重复的记录和重复记录里最后插入的一条记录

select a.* from test1 a where rowid =(select max(rowid) from test1 b where a.name=b.name);

  

7 使用rowid 查询得到不重复的记录和重复记录里最先插入的记录

select * from test1 a where  rowid = (select min(rowid) from test1 b where b.name = a.name);

  

删除  所有重复不保留任何一条

delete  from test1 a where exists ( select name from (select name ,count(*) from test1  group  by name having count(*)>1) b where a.name = b.name);

  

delete from test1 a where a.name in (select name  from test1  group  by name having count(*)>1);

  

删除重复记录里,第一条重复记录后面插入的记录

delete from test1 a where  rowid  !=(select min(rowid) from test1 b where b.name = a.name);

  

删除先前插入的重复记录,保留最后插入的重复记录

delete  from test1 a where rowid !=(select max(rowid) from test1 b where a.name=b.name);

  

oracle 查询及删除表中重复数据的更多相关文章

  1. 查询和删除表中重复数据sql语句

      1.查询表中重复数据.select * from peoplewhere peopleId in (select   peopleId   from   people   group   by   ...

  2. mysql 查询及 删除表中重复数据

    CREATE TABLE `test` ( `id` INT(20) NOT NULL AUTO_INCREMENT, `name` VARCHAR(20) NULL DEFAULT NULL, `a ...

  3. ROWID面试题-删除表中重复数据(重复数据保留一个)

    /* ROWID是行ID,通过它一定可以定位到r任意一行的数据记录 ROWID DNAME DEPTNO LOC ------------------ ------------------------ ...

  4. sqlite 删除表中重复数据(亲测可用)

    例子:表名  Paper .通过字段PaperID查找重复数据. 1 --查询某表中重复的数据       select * from Paper group by PaperID having co ...

  5. sql记录去重(SQL查询或者删除表中重复记录)

    .查找表中多余的重复记录,重复记录是根据单个字段(peopleId)来判断 select*from people where peopleIdin (select peopleIdfrom peopl ...

  6. MySQL 数据库删除表中重复数据

    采集数据的时候,由于先期对页面结构的分析不完善,导致采漏了一部分数据.完善代码之后重新运行 Scrapy,又采集了一些重复的数据,搜了下删除重复数据的方法. N.B. 删除数据表的重复数据时,请先备份 ...

  7. Oracle通过ROWID删除表中重复记录

    -- 1 通过ROWID删除T1表里重复的记录    SELECT ROWID,A,B--DELETE FROM  T1WHERE ROWID IN (  SELECT RD  FROM  (     ...

  8. oracle查询、删除表中相同的数据

    delete FROM tablename a WHERE rowid > ( SELECT min(rowid) FROM tablename b WHERE b.id = a.id and ...

  9. SQL Server中删除表中重复数据

    方法一:利用游标,但要注意主字段或标识列 declare @max integer,@id integer open cur_rows fetch cur_rows into @id,@max beg ...

随机推荐

  1. timer实现Grid自动换行(连续相同的id跳到下一行)

    private { Private declarations } FRow: Integer; procedure SetRow(const Value: Integer); public { Pub ...

  2. Ubuntu配置ip和dns后还是不能访问外网

    https://blog.csdn.net/WFping518/article/details/81011722

  3. Markdown使用心得

    1. 标题的使用 在使用标题时,如果为了层次清晰,可以在"#"后加上"1. "或者"1.1. "这种序号. 每一级标题的正文结束后,最好加一 ...

  4. [SinGuLaRiTy] 2017 百度之星程序设计大赛 初赛A

    [SinGuLaRiTy-1036] Copyright (c) SinGuLaRiTy 2017. All Rights Reserved. 小C的倍数问题 Time Limit: 2000/100 ...

  5. linux下Tomcat+OpenSSL配置单向&双向认证(自制证书)

    背景 由于ios将在2017年1月1日起强制实施ATS安全策略,所有通讯必须使用https传输,本文只针对自制证书,但目前尚不确定自制证书是否能通过appstore审核. 1.必须支持传输层安全(TL ...

  6. Python——requests的安装及入门-贴吧爬虫

    一.windows平台下requests的安装 1.win+R,输入cmd,打开命令行窗口,输入命令:pip install requests ,即可自动安装库成功 2.输入命令:pip list,即 ...

  7. P4854 MloVtry的咸鱼树 状压+最短路

    $ \color{#0066ff}{ 题目描述 }$ 俗话说种瓜得瓜,种豆得豆,MloVtry把自己砍掉一半埋进了土里,于是它得到了一颗n个点的咸鱼树. 但是问题是由于MloVtry只舍得埋下一半的自 ...

  8. php中的openssl开启方法

    windows下开启方法: 1: 首先检查php.ini中:extension=php_openssl.dll是否存在, 如果存在的话去掉前面的注释符‘:', 如果不存在这行,那么添加extensio ...

  9. RUCM简介

    一.动机 UCM:用例建模,主要用于结构化和文档需求方面. UCSs:用例规格说明书,通常是文本文档,所以描述中不可避免含有歧义. RUCM:限制性用例建模.目标 G1.使UCMs更加可理解并且更精确 ...

  10. 自动化上传图片,路径driver.find_element_by_id("oper-img-change").send_keys("C:\\Users\\76776\\Pictures\\logo.jpg"),为正确姿势,单\报错 'unicodeescape' codec can't decode bytes in position XXX: trun

    自动化上传图片,路径driver.find_element_by_id("oper-img-change").send_keys("C:\\Users\\76776\\P ...