Results 1 to 2 of 2
  1. #1
    Join Date
    May 2002
    Posts
    2

    Unanswered: Count & Distinct

    Hi,

    I was wondering if these two queries (or ways to get the total number of unique names in a table) are the same?

    1. SELECT DISTINCT names FROM users;
    and then get from mysql_num_rows

    2. SELECT COUNT(DISTINCT names) FROM users;

    And if they're the same, I guess the #2 is more efficient?
    Thanks

  2. #2
    Join Date
    Feb 2002
    Posts
    2,232
    It would depend on your scenario. If you only want the number of distinct values, then yes, #2 is the best path. If you want to use the distinct values in addition to knowing the number of rows then #1 would be your best path.

Posting Permissions

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