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

Home -> Community -> Mailing Lists -> Oracle-L -> Re: SQL question

Re: SQL question

From: Tom Wheltle <twheltle_at_US.NET>
Date: Fri, 12 Jan 1996 16:47:19 -0500
Message-Id: <9601122207.AA08204@alice.jcc.com>


Re:

>Hi! I would appreciate help on the following SQL question. I have a
>table that contains data such as:
>ID Name Value1 Value2 Systime
>---- ------ ------ ------ -------
>1 AAA 10 25 01-Jan-1996
>1 BBB 100 250 01-Dec-1995
>1 AAA 20 50 10-Jan-1996
>1 BBB 200 20 05-Jan-1996
>1 MMM 250 240 11-Jan-1996
>etc.
>
>I would like to write a SQL statement to return the name, value1, value2
>and systime where the systime is the most recent for a distinct name. For
>instance, the output would give me the row with name AAA and systime
>10-Jan-1996 and
>

Have you tried a synchronized sub-query? Try something like:

        select a.name, a.value1, a.value2, a.systime
        from   table a
        where  a.systime = (select max(b.systime)
                            from   table b
                            where  b.name = a.name);

HTH, Tom



Tom Wheltle, Principal Consultant
Wheltle Associates
Rockville, MD                                twheltle_at_us.net

Received on Fri Jan 12 1996 - 17:07:22 CST

Original text of this message

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