COUNT of DISTINCT Rows in SQL Server






4.13/5 (7 votes)
COUNT of DISTINCT Rows in SQL Server
SQL Server does not support
COUNT(DISTINCT *)
. For example, the below query fails.
SELECT COUNT(DISTINCT *) FROM EmployeesThe error message generated is:
Incorrect syntax near '*'
Instead, use the below query:
SELECT COUNT(*) FROM (SELECT DISTINCT * FROM Employees) EmpNote: This is specifically useful when you want 'DISTINCT *' - without coloumn name(s)