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

Home -> Community -> Usenet -> c.d.o.tools -> Re: please help with SQL query...

Re: please help with SQL query...

From: <tommychill_at_my-deja.com>
Date: Thu, 24 Aug 2000 18:28:43 GMT
Message-ID: <8o3pfu$6f8$1@nnrp1.deja.com>

Unless someone comes up with a prettier solution, try this:

SELECT MessageID(PK)
FROM (SELECT OriginalMessageID, MAX(ExecDate) MAXDATE

        FROM   table_name
        GROUP BY OriginalMessageID) a, table_name b
WHERE MAXDATE = b.ExecDate
AND a.OriginalMessageID = b.OriginalMessageID;

Should work, even though its not so pretty...

In article <JCcp5.15372$Z2.182255_at_nnrp1.uunet.ca>,   "Massimo Di Marco" <massimo_at_sfcommerce.com> wrote:
> I need some help to figure out how to do this query...
>
> Here is the data:
>
> OriginalMessageID MessageID(PK) ExecDate
> 1 1234 10:20
> 1 5FE2 10:55
> 1 EA33 10:50
> 2 4667 11:10
> 2 98EA 10:13
>
> Now I need the MessageID for the latest record for each
 OriginalMessageID,
> so the result would be:
>
> MessageID(PK)
> 5FE2
> 4667
>
> What would the SQL SELECT look like to get this result....
>
> Thanks
> Massimo
>
>

Sent via Deja.com http://www.deja.com/
Before you buy. Received on Thu Aug 24 2000 - 13:28:43 CDT

Original text of this message

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