Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!gem.mps.ohio-state.edu!ginosko!uunet!cyclops!csense!bote From: bote@csense.UUCP (John Boteler) Newsgroups: comp.databases Subject: Re: Deleting duplicate records Message-ID: <305@csense.UUCP> Date: 17 Jul 89 15:25:20 GMT References: <9426@phoenix.Princeton.EDU> Organization: Common Sense Computing, McLean Va Lines: 32 From article <9426@phoenix.Princeton.EDU>, by englandr@phoenix.Princeton.EDU (Scott Englander): > I'd like to delete duplicate records in a FoxBase file. I tried setting > the index to unique and then copying the database to a new file, but the > duplicates remained. I ultimately did it with a simple and SLOW program > that checked for duplicates and deleted them (as i'm typing, it's > running in the background under Multifinder -- there are 4000 records!). > But there must be a better way to do this using the unique index, since > only the first record with a given value of the index field is indexed. Assuming that a 'duplicate record' in your case is one which has the same key as another, and the other fields do not enter into the decision, here is one suggestion: set unique on use &tablename index &indexname go top do while .not. eof() delete && marks this record to be copied later skip && advances to next unique record in index enddo copy to &temp for deleted() && copy only those marked !mv tablename.dbf tablename.old !mv temp.dbf tablename.dbf go home && relax! Now, before you remove the old file, are you sure that those records which did not make it into the new file are truly bogus? rm is forever. -- Bote uunet!cyclops!csense!bote {mimsy,sundc}!{prometheus,hqda-ai}!media!cyclops!csense!bote