Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Want to remove duplicates from a table
Message
 
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Divers
Thread ID:
00406787
Message ID:
00406851
Vues:
36
>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
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform