List:MySQL on Win32« Previous MessageNext Message »
From:SGreen Date:July 16 2004 12:58pm
Subject:Re: DISTINCT query
View as plain text  
This will give you the last 15 unique recipients (as determined by their 
ID value):

SELECT MAX(ID), recipients
FROM log_table
GROUP BY recipients
ORDER BY MAX(ID) desc
LIMIT 15

When we use the MAX() function we find out when the last time a recipient 
was added to the table. By sorting on the MAX(ID)s we get the most 
recently added names in their  order of increasing history. 

Yours,
Shawn Green
Database Administrator
Unimin Corporation - Spruce Pine

labsy@stripped wrote on 07/15/2004 10:57:49 PM:

> Hello!
> 
> could you please help me construct proper mysql query. I spent 8 hours
> with testing, but no proper results :((
> 
> I have a LOG with at least "ID" and "recipient" fields.
> I want to extract last 15 different recipients.
> 
> I tried this:
> SELECT ID DISTINCT recipients
> FROM log_table
> GROUP BY recipients
> ORDER BY ID DESC 
> LIMIT 15
> 
> But this returns some unknown 15 different recipients, but not 15
> last. Could you help me, please?
> 
> 
> 
> 
> -- 
> Regards,
> Andrej
> --------------------------------
> e-mail:         labsy@stripped
> Tel.:        +386 (0)7 45 210 44
> GSM :         +386 (0)41 233 335
> --------------------------------
> 
> 
> 
> 
> -- 
> MySQL Windows Mailing List
> For list archives: http://lists.mysql.com/win32
> To unsubscribe:    http://lists.mysql.com/win32?unsub=1
> 

Thread
DISTINCT querylabsy16 Jul
  • Re: DISTINCT querySGreen16 Jul