Results 1 to 4 of 4
  1. #1
    Join Date
    Nov 2003
    Location
    Sinapore
    Posts
    187

    Unanswered: Get count of distinct dates

    Hi everyone,

    This seems like a trivial query but I can't figure out how to do it

    How do you get a count of the number of distinct dates in a table?

    Suppose I've:

    2010-03-10
    2010-03-08
    2010-03-10
    2010-02-10
    2010-02-10
    2010-01-24

    There are four distinct dates - I'm trying to get that number.

    Thanks in advance

    (Ah sorry, I kept getting Gateway error and I thought the submission didn't go through - but it did. Didn't know I can't delete my own posts after I saw the duplicates.)
    Last edited by pearl2; 03-11-10 at 13:29.

  2. #2
    Join Date
    Jun 2007
    Location
    London
    Posts
    2,527
    Code:
    select count(distinct fieldname) from table
    PS I deleted the duplicate posts

  3. #3
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    SELECT COUNT(*) FROM ( SELECT columnname FROM daTable GROUP BY columnname ) AS tadaaaa

    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  4. #4
    Join Date
    Nov 2003
    Location
    Sinapore
    Posts
    187
    Wonderful! Thank you so much, Mike and r937

    I swear I've tried queries like yours, with near misses.

    Cheers!

Posting Permissions

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