简体   繁体   English

甲骨文| 删除重复记录

[英]oracle | delete duplicates records

I have identified some duplicates in my table: 我在表中发现了一些重复项:

-- DUPLICATES: ----
select   PPLP_NAME,
         START_TIME,
         END_TIME,
         count(*)
from  PPLP_LOAD_GENSTAT
group by PPLP_NAME,
         START_TIME,
         END_TIME
having   count(*) > 1
-- DUPLICATES: ----

How is it possible to delete them? 如何删除它们?

I'd suggest something easier: 我建议一些简单的事情:

CREATE table NewTable as
SELECT DISTINCT pplp_name,start_time,end_time
FROM YourTable

Then delete your table, and rename the new table. 然后删除表,然后重命名新表。

If you really want to delete records, you can find a few examples of how here. 如果您确实要删除记录, 可以在此处找到一些示例。

Even if you don't have the primary key, each record has a unique rowid associated. 即使您没有主键,每个记录也会有一个唯一的关联的rowid。

By using the query below you delete only the records that don't have the maximum row id by self joining a table with the columns that cause duplication. 通过使用下面的查询,您可以通过将表与导致重复的列进行自我连接来仅删除没有最大行ID的记录。 This will make sure that you delete any duplicates. 这将确保您删除所有重复项。

DELETE FROM PPLP_LOAD_GENSTAT plg_outer
WHERE ROWID NOT IN(
  select   MAX(ROWID)
  from     PPLP_LOAD_GENSTAT plg_inner
  WHERE    plg_outer.pplp_name = plg_inner.pplg_name
  AND      plg_outer.start_time= plg_inner.start_time
  AND      plg_outer.end_time  = plg_inner.end_time
);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM