Could someone please explain the below query? ID is not PK and there can be multiple rows for same ID. This query gets latest row.
SELECT ID, SCORE, DATE_OF_SCORE FROM
(
SELECT ID, SCORE, DATE_OF_SCORE, ROW_NUMBER() OVER (PARTITION BY ID ORDER BY DATE_OF_SCORE DESC) RN
FROM PERSON_SCORE_DETAILS
WHERE ID = 123
)
WHERE RN = 1;
This query selects the score at the most recent date_of_score for id 123.
The partition by clause here is redundant since you are only selecting one id.
And this type of query is better handled by using an aggregate, like this:
Or even simpler:
Regards,
Rob.