select max date from joined tables with columns with unique values

Hi I am at my wits end!

I want to get the most recent date from joined tables with unique values in 2 columns. How do I do this? I have also tried the ranking (but John has the same rank) and tried rownum = 1, but I still get the same results below for some reason
  1. Name     ID            Email                  DeptNum      DeptScore      OnDate
  2. John     A46            100                  50                  5/11/2011
  3. John     A46      200                  75                   7/21/2015
  4. Alice    B33      100                  50                  4/15/2014

I want to get the following:
  1. Name     ID            Email                  DeptNum      DeptScore      OnDate
  2. John     A46      200                  75                   7/21/2015
  3. Alice    B33      100                  50                  4/15/2014

My query (oracle)
select distinct,,, d.deptnum, d.deptscore, d.ondate
from  emp e
inner join dept d on d.deptnum = e.dnum
    and d.ondate = e.livedate
    and d.ondate = (select max(m.ondate) from dept m where d.ondate = m.ondate)
--where in ('A46','B33')

Open in new window

Ramanth LexAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

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.

How about this?

SELECT name,
               ROW_NUMBER() OVER(PARTITION BY name, id ORDER BY ondate DESC) rn
          FROM emp e INNER JOIN dept d ON d.deptnum = e.dnum AND d.ondate = e.livedate)
 WHERE rn = 1

Open in new window

If it doesn't produce the desired results, please post data for emp and dept (each table, not the results of a join) that produce wrong results.

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
Ramanth LexAuthor Commented:
Thank you, good sir!!
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

From novice to tech pro — start learning today.