DBAsupport.com Forums - Powered by vBulletin
Results 1 to 6 of 6

Thread: Distinct Records with a count

  1. #1
    Join Date
    Dec 2000
    Posts
    5

    Question

    Is it possible to return all distinct records in a column as well as count of each distinct records:

    example: I have a column called sID which may contain duplicate ids.

    SID COUNT
    ---- -------
    K13R 1
    K14R 2
    K15R 1
    K17T 4


    I havent been able to figure how to use the count function with the distinct keyword. I am not sure if that is the right approach anyway.

    All assistance will be greatly appreciated.

  2. #2
    Join Date
    Nov 2000
    Location
    Baltimore, MD USA
    Posts
    1,339
    Not exactly sure what you're asking. Could you please show the result set you would expect using your example?

    Thanks,

    - Chris

  3. #3
    Join Date
    Oct 2000
    Posts
    90
    I think you need to use the group by, so it might look something like

    select sid, count(*)
    from table
    group by sid

  4. #4
    Join Date
    Jul 2000
    Posts
    37
    Hi,

    I'm not sure if this is what you're after, but can't you
    just use

    select distinct col_name, count(*)
    group by col_name
    /

    Cheers

    chris.

  5. #5
    Join Date
    Jul 2000
    Posts
    37
    Exactly, m1l,

    you don't need the distinct anyway with the group by.

  6. #6
    Join Date
    Dec 2000
    Posts
    23
    hi,

    I think this may solve ur problem

    select count(distinct(sid)) from tablename;

    its counts the distinct values in a table only
    sridhar garige

Posting Permissions

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


Click Here to Expand Forum to Full Width