Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Why does this work?
Message
 
 
À
16/10/2010 11:01:37
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Versions des environnements
SQL Server:
SQL Server 2008
Divers
Thread ID:
01485726
Message ID:
01485739
Vues:
75
It's other way around. You have to group on any none-aggregated columns in the query column list. You're not required to include columns you group on in the query result.


>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)
>
>
--sb--
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform