博客
关于我
oracle数据表删除重复数据
阅读量:590 次
发布时间:2019-03-11

本文共 1295 字,大约阅读时间需要 4 分钟。

去重查询:

SQL> select * from flash_tbl;

 

ID VL

---------- --

10 I

11 J

12 K

13 L

14 M

15 N

16 O

17 P

18 Q

19 R

20 S

 

ID VL

---------- --

1 /

2 A

3 B

4 C

5 D

6 E

7 F

8 G

9 H

1 /

2 A

 

ID VL

---------- --

3 B

4 C

5 D

6 E

7 F

8 G

9 H

1 /

2 A

3 B

4 C

 

ID VL

---------- --

5 D

6 E

7 F

8 G

9 H

 

38 rows selected.

SQL> select distinct id,vl from flash_tbl;

ID VL

---------- --

11 J

14 M

7 F

8 G

20 S

4 C

5 D

12 K

16 O

17 P

1 /

 

ID VL

---------- --

10 I

13 L

2 A

3 B

15 N

18 Q

6 E

9 H

19 R

20 rows selected.

删除重复数据(两种方式)

SQL> select * from flash_tbl a where rowid !=(select max(rowid) from flash_tbl b where a.id=b.id);    -----查出重复数据

SQL> delete from flash_tbl a where rowid !=(select max(rowid) from flash_tbl b where a.id=b.id);      -----删掉重复数据

-----------------------------------------------------------------------------------------------------------------------------------

SQL> select * from flash_tbl where Id in (select Id from flash_tbl group by Id having count(Id) > 1);    -----查出重复数据

SQL> delete from flash_tbl where Id in (select Id from flash_tbl group by Id having count(Id) > 1) and rowid not in (select min(rowid) from flash_tbl group by Id having count(Id)>1);     -----删掉重复数据

------------------------------------------------------------------------------------------------------------------------------------

 

转载地址:http://advtz.baihongyu.com/

你可能感兴趣的文章
Manjaro 24.1 “Xahea” 发布!具有 KDE Plasma 6.1.5、GNOME 46 和最新的内核增强功能
查看>>
mapping文件目录生成修改
查看>>
MapReduce程序依赖的jar包
查看>>
mariadb multi-source replication(mariadb多主复制)
查看>>
MaterialForm对tab页进行隐藏
查看>>
Member var and Static var.
查看>>
memcached高速缓存学习笔记001---memcached介绍和安装以及基本使用
查看>>
memcached高速缓存学习笔记003---利用JAVA程序操作memcached crud操作
查看>>
Memcached:Node.js 高性能缓存解决方案
查看>>
memcache、redis原理对比
查看>>
memset初始化高维数组为-1/0
查看>>
Metasploit CGI网关接口渗透测试实战
查看>>
Metasploit Web服务器渗透测试实战
查看>>
Moment.js常见用法总结
查看>>
MongoDB出现Error parsing command line: unrecognised option ‘--fork‘ 的解决方法
查看>>
mxGraph改变图形大小重置overlay位置
查看>>
MongoDB学习笔记(8)--索引及优化索引
查看>>
MQTT工作笔记0009---订阅主题和订阅确认
查看>>
ms sql server 2008 sp2更新异常
查看>>
MS UC 2013-0-Prepare Tool
查看>>