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: Kevin Lange <kgel_at_ppoone.com>
Date: Fri, 31 May 2002 08:28:45 -0800
Message-ID: <F001.0047103C.20020531082845@fatcity.com>


Try this

select a.f1, a.d1, a.d2
from
  (select field1 f1,date1 d1,max(date2) d2 from temp group by field1,date1) a,
  (select field1 f1,date1 d1,max(date2) d2 from temp group by field1,date1) b
where a.f1 = b.f1
and a.d1 < b.d1
and a.d2 > b.d2

-----Original Message-----
Sent: Friday, May 31, 2002 10:59 AM
To: Multiple recipients of list ORACLE-L

Hi,

    I have a table with 1 field and 2 dates: field1, date1, date2. I need to find the max value of date2 for all the field1, date1 combinations. Then I want to join the table to itself on field1 and find all the rows where field1 matches, date1 < date1, and max(date2) > max(date2). I did this in 2 queries. First I created a view as follows:

create view v1 (f1, d1, d2)
as select field1,date1,max(date2) from table1 group by field1,date1;

Then I joined the 2 views together like this:

select a.f1,a.d1,a.d2 from v1 a, v1 b
where a.f1 = b.f1
and a.d1 < b.d1
and a.d2 > b.d2;

    This worked fine, but I was wondering if there was a way to do this in one query without having to create a view.

Bill Carle
AT&T
Database Administrator
816-995-3922
wcarle_at_att.com

--

Please see the official ORACLE-L FAQ: http://www.orafaq.com
--

Author: Carle, William T (Bill), ALCAS
  INET: wcarle_at_att.com

Fat City Network Services    -- (858) 538-5051  FAX: (858) 538-5051
San Diego, California        -- Public Internet access / Mailing Lists
--------------------------------------------------------------------
To REMOVE yourself from this mailing list, send an E-Mail message to: ListGuru_at_fatcity.com (note EXACT spelling of 'ListGuru') and in the message BODY, include a line containing: UNSUB ORACLE-L (or the name of mailing list you want to be removed from). You may also send the HELP command for other information (like subscribing).
--

Please see the official ORACLE-L FAQ: http://www.orafaq.com
--

Author: Kevin Lange
  INET: kgel_at_ppoone.com
Fat City Network Services    -- (858) 538-5051  FAX: (858) 538-5051
San Diego, California        -- Public Internet access / Mailing Lists
--------------------------------------------------------------------
To REMOVE yourself from this mailing list, send an E-Mail message to: ListGuru_at_fatcity.com (note EXACT spelling of 'ListGuru') and in the message BODY, include a line containing: UNSUB ORACLE-L (or the name of mailing list you want to be removed from). You may also send the HELP command for other information (like subscribing). Received on Fri May 31 2002 - 11:28:45 CDT

Original text of this message

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