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

  • I believe Sean's solution has an extra unnecessary step.

    If to use the filtering subquery in the JOIN it may provide sorting criteria as well.

    Then CTE query may be excluded:

    SELECT *

    FROM @mySampleTable s

    INNER JOIN (SELECT CaseID, MAX(CreatedDate) LatestUpdate

    FROM @mySampleTable

    GROUP BY CaseID

    HAVING MAX(StudentID) != MIN(StudentID)) fs ON s.CaseID = fs.CaseID

    ORDER BY LatestUpdate DESC, CreatedDate DESC

    _____________
    Code for TallyGenerator