distinct count of multiple columns

  • This appears to not be allowed. Any suggestions?

    FWIW, I am trying something like the following...

    SELECT COUNT( DISTINCT col1, col2, col3 ) FROM table

  • It seems not, however you can change it to something like this:

    SELECT COUNT(*)

    FROM

    (

    SELECT col1, col2, col3

    FROM table

    GROUP BY col1, col2, col3

    ) X

    Ronald HensbergenHelp us, help yourself... Post data so we can read and use it: http://www.sqlservercentral.com/articles/Best+Practices/61537/-------------------------------------------------------------------------2+2=5 for significant large values of 2

  • Wonderful. Thank you.

    r.hensbergen (1/29/2009)


    It seems not, however you can change it to something like this:

    SELECT COUNT(*)

    FROM

    (

    SELECT col1, col2, col3

    FROM table

    GROUP BY col1, col2, col3

    ) X

  • Bonkers :hehe:, am I missing something, did you want a count of each distinct column or simply to count all the records in the table: count(*)?

    Please try:

    SELECT COUNT( DISTINCT col1 ), COUNT( DISTINCT col2 ), COUNT( DISTINCT col3 )

    FROM table

    This will give you a distinct number of records in each column.

    Max

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply