Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Mailing Lists -> Oracle-L -> SQL Question
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). Received on Fri May 31 2002 - 10:58:47 CDT
![]() |
![]() |