count multiple distinct columns

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Dean

    count multiple distinct columns

    I want to build query to return how many rows are in this query:
    select distinct c1, c2 from t1

    But SQL won't accept this syntax:
    select count (distinct c1, c2) from t1

    Does someone know how to count multiple distinct columns? Thanks.



    --
    Disclaimer: This post is solely an individual opinion and does not speak on
    behalf of any organization.


  • Dan Guzman

    #2
    Re: count multiple distinct columns

    One method is to use a derived table:

    SELECT COUNT(*)
    FROM (
    SELECT DISTINCT c1, c2
    FROM t1) AS t1

    --
    Hope this helps.

    Dan Guzman
    SQL Server MVP

    "Dean" <noreply@fakead dress.com> wrote in message
    news:cd1o36$aho $1@news01.intel .com...[color=blue]
    > I want to build query to return how many rows are in this query:
    > select distinct c1, c2 from t1
    >
    > But SQL won't accept this syntax:
    > select count (distinct c1, c2) from t1
    >
    > Does someone know how to count multiple distinct columns? Thanks.
    >
    >
    >
    > --
    > Disclaimer: This post is solely an individual opinion and does not speak[/color]
    on[color=blue]
    > behalf of any organization.
    >
    >[/color]


    Comment

    • Dean

      #3
      Re: count multiple distinct columns

      "Dan Guzman" <danguzman@nosp am-earthlink.net> wrote in message
      news:8D_Ic.1568[color=blue]
      > One method is to use a derived table:
      >
      > SELECT COUNT(*)
      > FROM (
      > SELECT DISTINCT c1, c2
      > FROM t1) AS t1[/color]

      Thanks! I was trying
      SELECT COUNT(*) FROM (SELECT DISTINCT c1, c2 FROM t1)
      but it wouldn't work without the "AS t1" at the end.

      --
      Disclaimer: This post is solely an individual opinion and does not speak on
      behalf of any organization.


      Comment

      • JK

        #4
        Re: count multiple distinct columns

        Try this out..

        SELECT COUNT(*) FROM (select distinct c1, c2 from t1)T

        Comment

        Working...