Delete duplicate records

Hi,

I’m uploading excel files to my server to import into my db. I need to delete duplicate combo primary key values from the temp table created. So far I have:

sc_exec_sql("select PARPRT_02, COMPRT_02, count()
from table_name
group by PARPRT_02, COMPRT_02
having count(
) > 1
DELETE FROM Product_Structure_[PMdate] WHERE PARPRT_02 ");

but I am not grasping how to accomplish the finishing blow.

Thanks,
Damian

Assuming you have a unique ID on each record, you could do something lime

DELETE a
FROM table_nameas a, table_nameas b
WHERE
(a.PARPRT_02 = b.PARPRT_02 OR a.PARPRT_02 IS NULL AND b.PARPRT_02 IS NULL)
AND (a.COMPRT_02 = b.COMPRT_02 OR a.COMPRT_02 IS NULL AND b.COMPRT_02 IS NULL)
AND a.ID < b.ID;

Hi William,
it is a Primary combo key of PARPRT_02 AND COMPRT_02. I’ll give this a try.

Thanks :slight_smile: