If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Get count of distinct dates

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-11-10, 12:20
pearl2 pearl2 is offline
Registered User
 
Join Date: Nov 2003
Location: Sinapore
Posts: 187
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 12:29.
Reply With Quote
  #2 (permalink)  
Old 03-11-10, 12:34
mike_bike_kite mike_bike_kite is offline
vaguely human
 
Join Date: Jun 2007
Location: London
Posts: 2,519
Code:
select count(distinct fieldname) from table
PS I deleted the duplicate posts
__________________
Mike
Reply With Quote
  #3 (permalink)  
Old 03-11-10, 13:02
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
SELECT COUNT(*) FROM ( SELECT columnname FROM daTable GROUP BY columnname ) AS tadaaaa

__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #4 (permalink)  
Old 03-11-10, 19:00
pearl2 pearl2 is offline
Registered User
 
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!
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On