我找到了以下删除重复项的方法:
DELETE FROM
table_name A
WHERE
a.rowid >
ANY (
SELECT
B.rowid
FROM
table_name B
WHERE
A.col1 = B.col1
AND
A.col2 = B.col2
);
有人可以一步一步地解释我的查询是如何工作的吗?
TIA!
答案 0 :(得分:1)
像这样:
DELETE FROM // The command to delete
table_name A //the table in which you want to remove duplicate
WHERE //condition
a.rowid > //checking the rowid which oracle adds to each row. Oracle Database rowid values contain information necessary to locate a row.
ANY ( //any row which has a condition
SELECT //select
B.rowid //rowid
FROM //from
table_name B //table name with alias name as B. Is used for making a self join
WHERE //condition
A.col1 = B.col1 //where the column1 has the same rowid
AND //and
A.col2 = B.col2 //where the column2 has the same rowid
);
答案 1 :(得分:1)
在Oracle中,ROWID是一个伪列,指向一行的物理位置。该查询执行自连接并获取具有相同值的第1列和第1列的那些行。第2列 - 假设这些密钥足以识别为重复行。
一旦获取了行,查询就会删除那些大于第一行读取的rowid,从而删除重复项