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

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

问题描述

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



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

解决方案

使用 rowid pseudocolumn。

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

其中 column1 column2 column3 组成每个记录的识别键。您可能会列出所有列。


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?

解决方案

Use the rowid pseudocolumn.

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

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

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

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