jasonhuibers
Programmer
Oracle 10G
Here is a sample of my query... It takes forever to run...
I have a list of records like this:
Column A Column B
12/25/2011 Stacey
12/01/2010 Brian
01/01/2009 John
10/10/2009 Steve
09/25/2011 Tim
I want to take the 3 max dates and values, the results to be:
12/25/2011 Stacey
09/25/2011 Tim
12/01/2010 Brian
SELECT
READ_DATE1, READ_DATE2, READ_DATE3
FROM
Table1,
Table2,
Table3
WHERE
Table1.ID = Table2.ID
AND Table2.ID = Table3.ID
AND and Table1.READ_DATE1 =
(select max(READ_DATE)
from Table3
where Table3.ID = Table1.ID)
AND and Table2.READ_DATE2 =
(select max(READ_DATE)
from Table4
where Table4.ID = Table2.ID
and READ_DTTM < Table1.READ_DATE1 )
AND and Table3.READ_DATE1 =
(select max(READ_DATE)
from Table5
where Table5.ID = Table1.ID
and READ_DTTM < Table2.READ_DATE1 )
Here is a sample of my query... It takes forever to run...
I have a list of records like this:
Column A Column B
12/25/2011 Stacey
12/01/2010 Brian
01/01/2009 John
10/10/2009 Steve
09/25/2011 Tim
I want to take the 3 max dates and values, the results to be:
12/25/2011 Stacey
09/25/2011 Tim
12/01/2010 Brian
SELECT
READ_DATE1, READ_DATE2, READ_DATE3
FROM
Table1,
Table2,
Table3
WHERE
Table1.ID = Table2.ID
AND Table2.ID = Table3.ID
AND and Table1.READ_DATE1 =
(select max(READ_DATE)
from Table3
where Table3.ID = Table1.ID)
AND and Table2.READ_DATE2 =
(select max(READ_DATE)
from Table4
where Table4.ID = Table2.ID
and READ_DTTM < Table1.READ_DATE1 )
AND and Table3.READ_DATE1 =
(select max(READ_DATE)
from Table5
where Table5.ID = Table1.ID
and READ_DTTM < Table2.READ_DATE1 )