Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Want to remove duplicates from a table
Message
 
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
00406787
Message ID:
00406804
Views:
29
>Have a free table that has duplicates on field1 and field2. I want to sort on field1,field2,field3 and remove all but the last duplicate from field1,field2.
>
>example. want to sort on lastname, firstname, add_date. if the lastname, firstname are duplciates want to keep only the one with the highest add_date.
>
>Can anyone help. thanks
>
>brenda

This is just a WAG off the top of my head:

select keyid, lastname+firstname customer, count(lastname+firstname), max(add_date) from mytable group by 2 having count(lastname+firstname) > 1 into cursor crsTemp

delete from mytable where keyid in (select keyid from crsTemp)

Of course, test on a copy of the table.
Mark McCasland
Midlothian, TX USA
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform