Re: sql query problem
From: Reinhard Kuhn <kuhn_at_cas-ps.com>
Date: 1996/01/22
Message-ID: <4dvkaa$iei_at_fred.cas-ps.com>#1/1
Date: 1996/01/22
Message-ID: <4dvkaa$iei_at_fred.cas-ps.com>#1/1
In article <4drcpq$236_at_inet-nntp-gw-1.us.oracle.com>, tkyte_at_us.oracle.com
says...
>
>Heather Dyson <heather.dyson_at_template.com> wrote:
>
>>I want to formulat a query so that I get only the rows with the greatest
>>month values for number and code. So the result of my query for the
>>example would be
>
>
>select *
> from T a
>where a.month = ( select max(MONTH)
> from T b
> where b.num = b.num
> and b.code = a.code )
>
>
>>I know this is probably easy, but I would appreciate any help.
>>Thanks,
>>Heather
>
>
>Thomas Kyte
>tkyte_at_us.oracle.com
>Oracle Government
>
select
*
from
T a
where
not exists ( select
null from T b where ( b.num = a.num ) and ( b.code = a.code ) and ( b.month > a.month ) ) -- _/_/_/ _/_/_/ _/ _/ // 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 Jan 22 1996 - 00:00:00 CET