shettybhas (5/22/2013)
Try the below query..SELECT *
FROM @mySampleTable s
OUTER APPLY (SELECT TOP 1 CaseID FROM @mySampleTable g WHERE s.CaseID = g.CaseID
ORDER BY CreatedDate DESC) h
This will give you lastest modified CaseID, and outerapply make qurery runs faster.
There is nothing in this query enforces order of records returned from @mySampleTable. So, records will be returned in random order.
Also, it doesn't perform required filtering. It will return all rows in a random order.
Basically the above query is exactly the same as simple:
SELECT * FROM @mySampleTable
Some redundant OUTER APPLY - nothing else.
Actually, have you compared its execution plan with INNER JOIN version? I'm in great doubt that it will be any faster...