How to count distinct values over multiple columns using SQL

404

nVector

posted on

Enjoy great content like this and a lot more !

Signup for a free account to write a post / comment / upvote posts. Its simple and takes less than 5 seconds




Maybe I am a lil old fashion, but why would not the following query work:

SELECT  DocumentId, DocumentSessionId,count(*)

FROM Table

group by DocumentId, DocumentSessionId

Sure. This query will produce the list of distinct groups and count per each group (the result will be one or more rows). The article is about, how to get distinct count for entire table (returns consolidated one row)