Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.server -> Re: SQL QUESTION

Re: SQL QUESTION

From: Matt Foster <matt_foster_uk_at_yahoo.co.uk>
Date: Tue, 19 Sep 2000 12:56:35 +0100
Message-ID: <39C75473.37B64A62@yahoo.co.uk>

Mark wrote:
>
> ggstr wrote:
> > i have a table with 3 fields : OBJECT,DATE,VALUE
> > every object can have many values with different date
> >
> > i want to display only the last value for each object(date most recently)
> > like this: object,date,value
> >
> > what is the good sql code to to this?
>
> SELECT MAX(date)
> ,object
> ,value
> FROM mytable
> GROUP BY object
> ,value
> /

I read the question more as:

SELECT     *
FROM       mytable
WHERE      (object, date) IN (SELECT object, MAX(date)
                              FROM   mytable
                              GROUP BY object)

i.e., finding the most recent record for each object and returning the value.

MF

-- 
matt_foster_uk_at_yahoo.co.uk
Received on Tue Sep 19 2000 - 06:56:35 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US