0

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?

Ori Marko
  • 56,308
  • 23
  • 131
  • 233
tln_jupiter
  • 153
  • 2
  • 8

2 Answers2

1

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.

sagi
  • 40,026
  • 6
  • 59
  • 84
1

Even if you don't have the primary key, each record has a unique rowid associated.

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. 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
);
Ucello
  • 226
  • 2
  • 16