Sql 在oracle中从表中删除重复数据

Sql 在oracle中从表中删除重复数据,sql,oracle,oracle11g,Sql,Oracle,Oracle11g,我有一个表副本,其中显示的数据如下: select * from ot.duplicate; 我想从我尝试的表中删除重复数据: delete from (select * from(select * from ot.duplicate a union select * from ot.duplicate b) t1); 但我得到了一个错误: ORA-01752: cannot delete from view without exactly one key-preserved table

我有一个表副本,其中显示的数据如下:

select * from ot.duplicate;
我想从我尝试的表中删除重复数据:

delete  from (select * from(select * from ot.duplicate a
union
select * from ot.duplicate b) t1);
但我得到了一个错误:

ORA-01752: cannot delete from view without exactly one key-preserved table

您应该尝试以下查询-

DELETE FROM ot.duplicate A
WHERE ROWID > (SELECT MIN(ROWID)
               FROM ot.duplicate B
               WHERE A.ID = B.ID
               AND A.NAME = B.NAME)

在SQL Server中应该是这样的

;with cte as (
select * from (
select id,name ,ROW_NUMBER() over(partition by name order by id) as trow from testt
) as p  
)

delete from cte where trow>1
您可以使用exists

干杯

Delete from your_table y1
Where exists (select 1 
From your_table y2
Where y1.id = y2.id
Abd y1.name = y2.name
And y1.rowid > y2.rowid);