从Oracle中的表中删除重复行 [英] Removing duplicate rows from table in Oracle

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

问题描述

我正在 Oracle 中测试一些东西并用一些示例数据填充了一个表,但在此过程中我不小心加载了重复记录,所以现在我无法使用某些列创建主键.

I'm testing something in Oracle and populated a table with some sample data, but in the process I accidentally loaded duplicate records, so now I can't create a primary key using some of the columns.

如何删除所有重复的行并只保留其中一个?

How can I delete all duplicate rows and leave only one of them?

推荐答案

使用 rowid 伪列.

DELETE FROM your_table
WHERE rowid not in
(SELECT MIN(rowid)
FROM your_table
GROUP BY column1, column2, column3);

其中 column1column2column3 构成每条记录的标识键.您可以列出所有列.

Where column1, column2, and column3 make up the identifying key for each record. You might list all your columns.

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

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