Count number of distinct rows with two fields as primary key

  • I have a table that I want to count the number of distinct rows in but I need base it off of two columns that make up the primary key.

    select distinct ReqID, ClientId from employees.

    How do I count the number of rows from the above query?

  • This may not be the most efficient way:

    SELECT COUNT(*)

    FROM (SELECT DISTINCT ReqID, ClientID FROM employees) E

    Seth Phelabaum


    Consistency is only a virtue if you're not a screwup. 😉

    Links: How to Post Sample Data[/url] :: Running Totals[/url] :: Tally Table[/url] :: Cross Tabs/Pivots[/url] :: String Concatenation[/url]

  • Awesome. I had forgotten to alias the select clause.

  • Maybe?

    SELECT count(DISTINCT str(ReqID) + str(ClientID)) FROM employees

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

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