Click here to Skip to main content
Click here to Skip to main content

Tagged as

COUNT of DISTINCT Rows in SQL Server

, 26 Nov 2010 CPOL
Rate this:
Please Sign up or sign in to vote.
COUNT of DISTINCT Rows in SQL Server
SQL Server does not support COUNT(DISTINCT *). For example, the below query fails.
The error message generated is:
Incorrect syntax near '*'
Instead, use the below query:
Note: This is specifically useful when you want 'DISTINCT *' - without coloumn name(s)


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author


India India
Ravikiran Malladi is a senior software professional in Microsoft technologies. He has global IT experience of over 10 years and has compulsive habit of writing tools, particularly for the projects he works on. He has vast experience in the roles of senior developer, technical analyst, technical architect besides in technical lead roles.
His hobbies include chess, music, cricket, web sites along side writing technical articles and technical blogs.

Comments and Discussions

GeneralMy vote of 1 Pinmemberkimberly wind21-Feb-13 18:52 
GeneralReason for my vote of 5 It works for DISTINCT but also work ... PinmemberSimon Dufour1-Dec-10 4:17 
GeneralReason for my vote of 3 gud 1 Pinmemberravindra_dhakate@rediffmail.com29-Nov-10 4:39 
GeneralReason for my vote of 5 Good Tip. PinmemberHiren Solanki29-Nov-10 3:00 
Reason for my vote of 5
Good Tip.

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.150327.1 | Last Updated 26 Nov 2010
Article Copyright 2010 by mravikiran
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid