Results 1 to 5 of 5
  1. #1
    Join Date
    Dec 2005
    Posts
    266

    Unanswered: count from distinct

    Hello

    for mS SQL 2000

    with

    SELECT DISTINCT Name, Region
    FROM Groups
    GROUP BY Name, Region


    I get 254 rows

    but how can I get the COUNT only ?

    something like

    SELECT COUNT(SELECT DISTINCT Name, Region
    FROM Groups
    GROUP BY Name, Region) AS CPT FROM Groups


    i must get 254

    thank you for helpings

  2. #2
    Join Date
    Jan 2006
    Location
    USA
    Posts
    115
    Change query according to your requirement...

    Code:
    USE Pubs
    
    select count (*) as row_count from (select type, pub_id from titles group by type, pub_id) t
    
    select type, pub_id from titles group by type, pub_id
    Rajesh Patel

    Everybody says - mistake is the first step of success, but it's not true. The correction of the mistake is the first step of success.

  3. #3
    Join Date
    Dec 2005
    Posts
    266
    it works perfetly

    thanks a lot Rajesh Patel

  4. #4
    Join Date
    Nov 2002
    Location
    Jersey
    Posts
    10,322
    Que?

    [s]SELECT COUNT(DISTINCT Name, Region)
    FROM Groups[/s]

    Doesn't work?

    EDIT: No it doesn't...but

    USE Northwind
    GO
    SELECT COUNT(DISTINCT CustomerID+CONVERT(varchar(10),EmployeeID)) FROM Orders


    Does
    Last edited by Brett Kaiser; 03-14-07 at 13:44.
    Brett
    8-)

    It's a Great Day for America everybody!

    dbforums Yak CorralRadio 'Rita
    dbForums Member List
    I'm Good Once as I ever was

    The physical order of data in a database has no meaning.

  5. #5
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    i'm liking rajesh's solution way more, brett
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •