+ Reply to Thread
Results 1 to 4 of 4

Thread: Duplicate keys

  1. #1
    Guest.Visitor Guest

    Default Duplicate keys

    I have a file with duplicate keys. I would like to eliminate all but one of the occurances of these duplicates. Is there a way to do this? thanks.

  2. #2
    Guest.Visitor Guest

    Default Duplicate keys

    R.O., I haven't tested this, but I believe it will work.
    Delete from lib/filnm f where rrn(f) in (select min(rrn(g)) from lib/filnm g where f.keyflda=g.keyflda and f.keyfldb=g.keyfldb having count(*)>1)
    This would be MUCH easier and faster in RPG. Bill R.O. Weber wrote: I have a file with duplicate keys. I would like to eliminate all but one of the occurances of these duplicates. Is there a way to do this? thanks.

  3. #3
    Guest.Visitor Guest

    Default Duplicate keys

    I usually use OPNQRYF to do this. There is a parameter called UNIQUEKEY that will select only the first record for unique each key value when the parm is set to *All. I use CPYFRMQRYF to create a temporary file, then a CPYF to replace the original with the temporary. Here is a CL example:
     PGM OVRDBF FILE(MASTER) SHARE(*YES) /*-- USE OPNQRYF TO SELECT ONLY UNIQUE KEYED RECORDS --*/ OPNQRYF FILE((MASTER)) KEYFLD(*FILE) UNIQUEKEY(*ALL) /*-- COPY UNIQUE KEYED RECORDS TO TEMPORARY FILE --*/ CPYFRMQRYF FROMOPNID(MASTER) TOFILE(QTEMP/MASTERTEMP) + CRTFILE(*YES) CLOF OPNID(MASTER) /*-- COPY TEMPORARY FILE BACK TO MASTER FILE, REPLACING RECORDS. --*/ CPYF FROMFILE(QTEMP/MASTERTEMP) TOFILE(MASTER) + MBROPT(*REPLACE) ENDPGM
    Mark McCall
    On Saturday, December 05, 1998, 07:41 AM, R.O. Weber wrote: I have a file with duplicate keys. I would like to eliminate all but one of the occurances of these duplicates. Is there a way to do this? thanks.

  4. #4
    Guest.Visitor Guest

    Default Duplicate keys

    On Saturday, December 05, 1998, 07:41 AM, R.O. Weber wrote: I have a file with duplicate keys. I would like to eliminate all but one of the occurances of these duplicates. Is there a way to do this? thanks. Many ways... but depending on your desire on how to have the duplicates resolved/handled, the request could be different. Do you desire to maintain as unique the first by relative record number, the first one entered into the DB, etc.? If there is a large amount of records but few duplicates you would do best to delete those which are selected as duplicates; position to and delete all those following with the nextequal. If there are mostly duplicates with fewer records, then insert into a unique keyed file of a selection of uniques from the original file is very quick; and with many records insert into non-keyed, and add the unique key later -- I am assuming you want rules to prevent the condition in the future. Regards, Chuck Comments provided "as is" with no warranties of any kind whatsoever.

+ Reply to Thread

Similar Threads

  1. Duplicate key with a deleted record
    By David Abramowitz in forum RPG
    Replies: 4
    Last Post: 04-20-2005, 06:38 AM
  2. RPG - Duplicate key on access path
    By David Abramowitz in forum Programming
    Replies: 4
    Last Post: 09-12-2001, 09:43 AM
  3. Duplicate records
    By Guest.Visitor in forum Application Software
    Replies: 3
    Last Post: 03-13-2000, 01:23 PM
  4. Duplicate Messages
    By Guest.Visitor in forum Analysis
    Replies: 2
    Last Post: 07-01-1998, 11:23 AM
  5. Duplicate keys
    By T.Holt in forum Programming
    Replies: 2
    Last Post: 06-03-1998, 06:26 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts