Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Delete all but the last
Message
 
 
À
12/08/2011 16:28:17
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Versions des environnements
Visual FoxPro:
VFP 7 SP1
OS:
Windows 7
Network:
Windows 2000 Server
Database:
Visual FoxPro
Application:
Desktop
Divers
Thread ID:
01520872
Message ID:
01520875
Vues:
63
>Hi. I have a database with a lot of duplicates (but it is ok). How can I mark/delete all but the last instance of each entry? Please keep in mind that I am in v.7.
>
>Thanks, Randy

Try
select max(ID) as IDToKeep, GroupID from myTable GROUP BY GroupID having count(*) > 1 into cursor Dups

delete from myTable where exists (select 1 from Dups where myTable.GroupID = Dups.GroupID and myTable.ID < Dups.IDToKeep)
If it's not broken, fix it until it is.


My Blog
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform