删除表中的重复行 [英] Remove duplicate rows in a table

查看:108
本文介绍了删除表中的重复行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



订单表



从表中可以看出,每个order_no都有几个重复项。所以我想要的是每个order_no只保留一行(不管是哪一个)



有谁知道该怎么做? (FYI,我使用Oracle 10)

解决方案

如果你不在乎每个order_no你得到哪一行,也许最简单的解决方案(Oracle 12之前)是:

 选择[无论你想要的列,可能不是rn  - 见下文] 
从(select order_table。*,
row_number()over(partition by order_no order by null)as rn

其中rn = 1
;


I have a table contains order information like below:

Order table:

As we can see from that table, each order_no has several duplicates. So what I want is to keep only one row for each order_no (no matter which one it is)

Is anyone knows how to do this? (FYI, I am using Oracle 10)

解决方案

If you don't care which row you get for each order_no, perhaps the simplest solution (before Oracle 12) is:

select [whatever columns you want, probably not rn - see below]
from ( select order_table.*,
              row_number() over (partition by order_no order by null) as rn
     )
where rn = 1
;

这篇关于删除表中的重复行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆