I asked almost the exact same question just a few days ago.

As of MySQL 3.23.2 you can use COUNT and DISTINCT together:

SELECT COUNT(DISTINCT ipAddress) ...

On 9/3/02 at 1:16 pm, Jeff Kilbride <[EMAIL PROTECTED]> wrote:

> I have a table with 3 fields:
> 
> initDate datetime not null
> id int unsigned not null
> ipAddress int unsigned not null
> 
> I'm trying to find the number of distinct ipAddresses associated with a
> particular id over a specified time frame -- for simplicity, let's say the
> time frame is the last 60 minutes. So, I use the following query:
> 
> SELECT DISTINCT ipAddress
> FROM table
> WHERE initDate >= DATE_ADD(now(), INTERVAL -60 MINUTE)
> AND id = [whatever id I'm looking for...];
> 
> This works and returns a result set with one row per distinct ipAddress.
In
> my program, I can count the number of rows in the result set to get my
> answer. My question is this: is there any way to modify this query so it
> returns a *count* of the number of distinct ipAddresses, rather than
having
> a row for each distinct ipAddress in the result set? Can I use some sort
of
> aggregate function like COUNT() when also specifying DISTINCT?
> 
> I've tried a few different things, but haven't been able to get it to
work.
> Does anyone know if this can or can't be done?
> 
> Thanks,
> --jeff
> 
> 
> 
> ---------------------------------------------------------------------
> Before posting, please check:
>    http://www.mysql.com/manual.php   (the manual)
>    http://lists.mysql.com/           (the list archive)
> 
> To request this thread, e-mail <[EMAIL PROTECTED]>
> To unsubscribe, e-mail <[EMAIL PROTECTED]>
> Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php
> 
> 


---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to