Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Why does this work?
Message
De
16/10/2010 11:01:37
 
 
À
Tous
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Titre:
Why does this work?
Versions des environnements
SQL Server:
SQL Server 2008
Divers
Thread ID:
01485726
Message ID:
01485726
Vues:
134
A program error (by yours truly) caused several rows to be duplicated in a client's table.

I needed a script to delete the dupes so I searched and found this little jewel.

Other scripts involve temporary tables, etc but this simple script works like a charm.

My newbie question is .. I thought you had to specify all the group by elements in the query result.
Obviously you don't.
What am I missing?
DELETE
FROM MyTable
WHERE ID NOT IN
(
SELECT MAX(ID)
FROM MyTable
GROUP BY DuplicateColumn1, DuplicateColumn2, DuplicateColumn3)
Anyone who does not go overboard- deserves to.
Malcolm Forbes, Sr.
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform