提出oracle表中重复行,Oracle 查找删除表中重复行的SQL

本文介绍了一种使用SQL查询来识别并处理重复记录的方法。通过两个不同的查询示例,展示了如何找到重复的数据项,并提供了删除多余重复项的建议方案。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

-- This query is not editable, but generally faster

Select

in_type,

in_type_serial,

count(*)

from ec_product_in

group by

in_type,

in_type_serial

having count(*) > 1

-- This query is editable, but generally slower

Select A1.id

from ec_product_in A1

where exists (Select 'x' from ec_product_in A2

where A1.in_type = A2.in_type

and a1.in_type_serial= A2.in_type_serial

and A1.ROWID <> A2.ROWID)

-- To delete all but one of each duplicate row,

-- change the first line to 'Delete'

-- and change the '<>' to '>' (keeps first duplicate)

-- or '

找出需要删除的行

/* Formatted on 2011-8-17 9:59:53 (QP5 v5.114.809.3010) */

-- This query is editable, but generally slower

SELECT A1.*, A1.ROWID

FROM ec_product_in A1

WHERE EXISTS

(SELECT 'x'

FROM ec_product_in A2

WHERE A1.in_type = A2.in_type

AND a1.in_type_serial = A2.in_type_serial

AND A1.ROWID <> A2.ROWID)

-- To delete all but one of each duplicate row,

-- change the first line to 'Delete'

-- and change the '<>' to '>' (keeps first duplicate)

-- or '

AND a1.id NOT IN

(SELECT A1.id

FROM ec_product_in A1

WHERE EXISTS

(SELECT 'x'

FROM ec_product_in A2

WHERE A1.in_type = A2.in_type

AND a1.in_type_serial =

A2.in_type_serial

AND A1.ROWID > A2.ROWID)-- To delete all but one of each duplicate row,

-- change the first line to 'Delete'

-- and change the '<>' to '>' (keeps first duplicate)

-- or '

)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值