I'm using Oracle SQL and trying to return the most recent category
dependent on the most_recent_date
. I am able to successfully pull the most_recent_date
per category
per part no/niin
, but I'm not able to get the full results I need.
I have the below query:
SELECT DISTINCT
contract,
part_no,
niin,
category,
MAX(date_entered) OVER(PARTITION BY contract, part_no, niin, category) most_recent_date
FROM
( **inner query** )
Current result:
CONTRACT PN NIIN 1T 01-AUG-08
CONTRACT PN NIIN 7T 19-APR-22
My End result for this needs to be just the line that has the most recent date. Line needed below:
CONTRACT PN NIIN 7T 19-APR-22
I have tried to nest the select statement again, to then try and choose the most recent line, but still received the same 2 lines. I also tried to use most_recent_date
within a grouping statement for category
and that didn't work either.
I'm sure it's a simple fix, but I'm not finding it.