how to retrieve the records with most recent date?

Folks,

I have written the below view to retrieve data from multiple tables and in the last line I am trying to retrieve the records with the most recent date instead of the fixed date below. Your suggestions would be appreciated. Thank you.

script excerpt:

"AND table.column >= trunc(to_date('30-03-2011'),'DD-MM-YYYY')"
cassie5643Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ajexpertCommented:
You may use ORDER BY CLAUSE DESC

Select * from tableA
ORDER BY DATE_COLUMN  DESC
0
Amitkumar PSr. ConsultantCommented:

Agreed with ajexpert.

Replace the following

AND table.column >= trunc(to_date('30-03-2011'),'DD-MM-YYYY')

with

order by table.column desc
0
cassie5643Author Commented:
thanks both... Is there a way to retrieve just the latest date instead of sorting?
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

slightwv (䄆 Netminder) Commented:
Can you provide more info?  Like sample data and expected results.

Until then why not a max?

select col1, col2, max(table.column)
from table
group by col1, col2
0
sdstuberCommented:

are you looking for something like this?

find most recent date value , then return all data for that date?


if so, try this...

select * from
(select t.*, rank() over(order by your_date desc) r  from your_table t)
where r = 1
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ajexpertCommented:
Other way of what sdstuber suggested
SELECT   *
  FROM   (SELECT   t.* ) r
            FROM   your_table t
           ORDER BY your_date DESC)
 WHERE   r = 1

Open in new window

0
sdstuberCommented:
there are some syntax errors, but also, that will only return 1 row
0
Amitkumar PSr. ConsultantCommented:
cassie5643,

Try the following.

select
    *
from
    YOUR_TABLE
where
    trunc(YOUR_TABLE.DATE_COLUMN) =
            (select
                trunc(max(YOUR_TABLE.DATE_COLUMN))
            from
                YOUR_TABLE);
0
sdstuberCommented:
I highly recommend NOT going with the MAX subselect,   the RANK query above does the same thing but doesn't require two IO's to the table.

But... Test both and confirm



Also, on my note to ajexpert earlier.  If there is only one row for a particular date, then the ROWNUM query will work just fine
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Oracle Database

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.