Originally posted by Rashmi Trivedi:
Hi All
I am trying to write an java application which has DB2400 database. The aim of this application is following
Find the duplicate records in table
Write them into CSV file
Keep the first records and delete the rest.
eg if you find, 10 duplicate records for given criteria, keep the 1st one from the list and delete 9 records.
I need some help "Keep the first records and delete the rest"..Could you please give me some help with coding..
Thank you in advance..
regards,
Rashmi Trivedi
Simplest way would be like this I think.
Create a new table (copy of old one)
Populate new table with all records of old table.
Truncate old table.
Optional - add primary key to old table. I would highly recommend this as to prevent duplicate records from coming back.
Now add records from new table back to old table but use a DISTINCT on the SELECT this time.
Then you have the old table with the duplicates removed and the new table has all the records and you can do as you like (dump to CSV and drop the table I suppose)