Removing duplicate rows from table in Oracle(从 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);
其中column1
、column2
和column3
构成了每条记录的标识键.您可以列出所有列.
Where column1
, column2
, and column3
make up the identifying key for each record. You might list all your columns.
这篇关于从 Oracle 表中删除重复行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:从 Oracle 表中删除重复行


基础教程推荐
- SQL Server 2016更改对象所有者 2022-01-01
- SQL Server 中单行 MERGE/upsert 的语法 2021-01-01
- 如何在 SQL Server 的嵌套过程中处理事务? 2021-01-01
- 将数据从 MS SQL 迁移到 PostgreSQL? 2022-01-01
- Sql Server 字符串到日期的转换 2021-01-01
- SQL Server:只有 GROUP BY 中的最后一个条目 2021-01-01
- 无法在 ubuntu 中启动 mysql 服务器 2021-01-01
- ERROR 2006 (HY000): MySQL 服务器已经消失 2021-01-01
- 在 VB.NET 中更新 SQL Server DateTime 列 2021-01-01
- 使用pyodbc“不安全"的Python多处理和数据库访问? 2022-01-01