Home Forums SQL Server 2008 T-SQL (SS2K8) List out rows from a duplicate record set that has one or more odd values RE: List out rows from a duplicate record set that has one or more odd values

  • 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...

    _____________________________________________
    "The only true wisdom is in knowing you know nothing"
    "O skol'ko nam otkrytiy chudnyh prevnosit microsofta duh!":-D
    (So many miracle inventions provided by MS to us...)

    How to post your question to get the best and quick help[/url]