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_at_yahoo.co.uk>
Date: Tue, 19 Sep 2000 12:56:35 +0100
Message-ID: <39C75473.37B64A62_at_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.ukReceived on Tue Sep 19 2000 - 13:56:35 CEST
