List:General Discussion« Previous MessageNext Message »
From:James Lockie Date:May 25 2007 7:59pm
Subject:Re: do I need 2 selects?
View as plain text  
Baron Schwartz wrote:
> Hi James,
>
> James Lockie wrote:
>> Say I have x rows of 2 columns each.
>> For example, 2 rows:  'A 10:00pm' and 'A 11:00pm'.
>>
>> I want to return one 'A' row with the latest time (eg. 'A 11:00pm).
>>
>> I could do 'select distinct(col1) from table' and then 'select
>> col1, max( col2 ) where col1=row[0]'?
>>
>> Is there a way to do it in one select?
>
> Yes.  Here are a bunch of different ways:
>
>
> http://www.xaprb.com/blog/2006/12/07/how-to-select-the-firstleastmax-row-per-group-in-sql/
> 
>
>
> Cheers
> Baron
>
Great, thanks.
Thread
do I need 2 selects?James Lockie25 May
  • Re: do I need 2 selects?Joerg Bruehe25 May
  • Re: do I need 2 selects?Baron Schwartz26 May
  • Re: do I need 2 selects?Reinhardt Christiansen26 May
Re: do I need 2 selects?James Lockie25 May