Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Take the top 3 max dates and value

Status
Not open for further replies.

jasonhuibers

Programmer
Sep 12, 2005
290
CA
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 )

 
What you posted as a query doesn't correspond to your data samples. For these samples you need to do
select top (3) Date, Name from dbo.YourTable ORDER BY [Date] Desc

PluralSight Learning Library
 
Jason

You state at the beginning of your post that this is for Oracle 10G. You've got the wrong forum as this one is for Microsoft SQL Server not Oracle. I suggest posting in the appropriate Oracle forum.

-SQLBill

The following is part of my signature block and is only intended to be informational.
Posting advice: FAQ481-4875
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top