Results 1 to 7 of 7
  1. #1
    Join Date
    Jul 2005
    Posts
    276

    Unanswered: count on distinct columns

    Hi all,

    I need to get a count of distinct columns in a table.

    If i give,

    select distinct col1,col2 from tabA;
    will display the distinct records but if I want just the #of records(count) then how do I do it?

  2. #2
    Join Date
    Aug 2003
    Location
    Where the Surf Meets the Turf @Del Mar, CA
    Posts
    7,776
    Provided Answers: 1
    >then how do I do it?
    By using the COUNT function
    You can lead some folks to knowledge, but you can not make them think.
    The average person thinks he's above average!
    For most folks, they don't know, what they don't know.
    Good judgement comes from experience. Experience comes from bad judgement.

  3. #3
    Join Date
    Jul 2005
    Posts
    276
    I did
    select count(distinct col1, col2) from tab1;

    but this gives me an error.

  4. #4
    Join Date
    Jun 2003
    Location
    West Palm Beach, FL
    Posts
    2,713

    Talking


    Try:
    Code:
    select count(distinct col1||col2) from tab1;


    The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb

  5. #5
    Join Date
    Jan 2004
    Location
    Croatia, Europe
    Posts
    4,094
    Provided Answers: 4
    Or perhaps
    Code:
    SELECT count(distinct col1), count(distinct col2) FROM tab1;
    I guess it would help if you show us some sample data and expected result.

  6. #6
    Join Date
    Mar 2002
    Location
    Reading, UK
    Posts
    1,137
    Or

    select count(*) from
    (
    select distinct col1, col2 from tableA
    )

    Alan

  7. #7
    Join Date
    Mar 2007
    Posts
    14
    Code:
    SELECT COUNT(A_COL1.col1), COUNT(A_COL2.col2)
     FROM 
      (SELECT DISTINCT col1 FROM tabA) A_COL1,
      (SELECT DISTINCT col2 FROM tabA) A_COL2;

Posting Permissions

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