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:
00406851
Views:
35
>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

Took me 3 queries:
select keyid, lname+fname customer, count(lname+fname), max(add_date) add_date ;
	from newstates ;
	group by 2 ;
	into cursor crsTemp

select a.lname+a.fname customer, a.keyid, a.add_date ;
	from newstates a, crsTemp b ;
	where a.lname+a.fname = b.customer and a.add_date = b.add_date ;
	order by a.lname, a.fname ;
	into cursor crsTemp2

delete from newstates where keyid not in (select keyid from crsTemp2)
Mark McCasland
Midlothian, TX USA
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform