Re: sql query problem

From: Chuck Hamilton <chuckh_at_ix.netcom.com>
Date: 1996/01/26
Message-ID: <4eb44p$2aq_at_cloner3.netcom.com>#1/1


Heather Dyson <heather.dyson_at_template.com> wrote:

>I have a table that has a primary key of
>number, code, month
 

>Let's say that I have the following data
 

>number code month
>------ ---- -----
>1 a 1
>1 b 1
>1 b 2
 

>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
 

>number code month
>------ ---- -----
>1 a 1
>1 b 2
 

>I know this is probably easy, but I would appreciate any help.
>Thanks,
>Heather

select * from table a
where month = (select max(month) from table b   where b.number = a.number and b.code = a.code)

--
Chuck Hamilton
chuckh_at_ix.netcom.com

Never share a foxhole with anyone braver than yourself!
Received on Fri Jan 26 1996 - 00:00:00 CET

Original text of this message