Re: Newbie : Find newest date
Date: 1995/11/13
Message-ID: <487nnm$ads_at_fred.cas-ps.com>#1/1
In article <Pine.SUN.3.91.951110104858.8403E-100000_at_seatimes>, sbut-is_at_seatimes.com says...
>
>
>On Thu, 9 Nov 1995, Jesper Clausen wrote:
>> Article Price Date
>> ---------------------------------------
>> a 2.00 11-NOV-93
>> a 2.50 11-NOV-95
>> b 1.00 11-DEC-94
>> b 2.40 06-JUN-95
>>
>> How do i create a select statement which retrieve the row with the highest
>> date ? - what i wan't is :
>>
>> a 2.50 11-NOV-95
>> b 2.40 06-JUN-95
>>
>
>select article, max(price), max(date) from mytable x
> where date=(select max(date) from mytable y
> where x.article = y.article)
> group by article;
>
or (for better performance)
select
article,price,date
from
mytable x
where
not exists ( select null from mytable y where y.article=x.article and y.date >x.date ) -- _/_/_/ _/_/_/ _/ _/ // Reinhard Kuhn / It can be _/ _/ _/ _/ _/ // (kuhn_at_cas-ps.com) / done quickly, _/_/_/ _/_/_/ _/_/ // CAS GmbH / cheaply or well _/ _/ _/ _/ _/ // Lemberger Strasse 14 / - pick any two! _/ _/ _/_/_/ _/ _/ // 66955 Pirmasens, Germany /Received on Mon Nov 13 1995 - 00:00:00 CET