Monday, September 10, 2007

Delete Duplicates:

Many times we come across a situation were we need to remove the duplicate records from the file which got inserted due to some problem with the keys or application.
The easy way to remove them is to use SQL for the same. Here is a SQL that helps in deleting the duplicate records from the file.
For example, consider a file FILEA in library LIBA and consider its key field to be KEYA. The query to delete the duplicate key records is as follows.
DELETE FROM LIBA/FILEA F1 WHERE RRN(F1) > (SELECT MIN(RRN(F2)) FROM FILEA F2 WHERE F2.KEYA=F1.KEYA)

No comments: