Why can\'t we use count(distinct *)
in SQL? As in to count all distinct rows?
You can try a CTE in Sql Server 2005
;WITH cte AS (
SELECT DISTINCT Val1,Val2, Val3
FROM @Table
)
SELECT COUNT(1)
FROM cte
To answer the question, From the documentation
Specifies that all rows should be counted to return the total number of rows in a table. COUNT() takes no parameters and cannot be used with DISTINCT. COUNT() does not require an expression parameter because, by definition, it does not use information about any particular column. COUNT(*) returns the number of rows in a specified table without getting rid of duplicates. It counts each row separately. This includes rows that contain null values.