Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Why does this work?
Message
 
 
To
16/10/2010 11:01:37
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Environment versions
SQL Server:
SQL Server 2008
Miscellaneous
Thread ID:
01485726
Message ID:
01485739
Views:
76
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--
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform