Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Deletion of Duplicate Records
Message
From
30/10/2000 14:11:27
 
 
To
30/10/2000 13:00:23
N. Lea
Nic Cross Enterprises
Valencia, California, United States
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
00435962
Message ID:
00436002
Views:
26
>I need some assistance with the deletion of duplicate records. I am working with a free table (no primary keys).
>
>What I am trying to accomplish is finding a prg to seek out all the duplicate values in the invoice_no field and delete them.
>
>can someone help me out?

Get duplicates:
select invoice_num, count(*) as ncnt ;
  from mytable ;
  group by invoice_num ;
  having count(*) > 1 ;
  into cursor cudupes
Which dupe to delete is another question. Assuming for this example that you want to keep the first entry of an invoice number and delete the rest:
SELECT mytable  
SET ORDER TO invoice_no && assuming there is an index on this, at least
SELECT cudupes

SCAN
  lcInv = invoice_no
  =SEEK(lcInv, "mytable")
  SKIP IN mytable
  DELETE WHILE invoice_no = lcInv IN mytable
ENDSCAN
For the future, I would suggest making the invoice_num index a CANDIDATE key, then trap for any candidate key violations when creating new invoice numbers.
Insanity: Doing the same thing over and over and expecting different results.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform