As you can see, PO number(PONo) ‘0050426995’ is duplicating. Because this table containing PO amendments too. If you notice, DownloadData is in order, meaning first version of PO received on 2010-06-26 17:07:04.910, rest of them subsequently.
The requirement is we want to get following output.
Normally we can write a sub query for this and get the output.
By running this query, you can see the following Actual Execution Plan.
From MS-SQL 2005 onwards this can be easily achieved by RANK() function.
Check its Actual Execution Plan and note the difference.