>>I need to update all duplicates by FK and Flag = 1 to set flag = 0 except for the latest by Date1 and Date2. I already did it by procedural code, but curious if it's possible to get the records to update by SQL.
>
>Basically you will be updating your table using the PK from ..
>
>selecting TOP 1 PK from (your duplicate selection statement) order by Date1 desc
>
>and
>
>selecting TOP 1 PK from (your duplicate selection statement) order by Date2 desc
Not exactly. I need to update all records which are duplicates except for the top 1. I guess in SQL Server you can use CTE to get all duplicates.
Still a bit tricky.
If it's not broken, fix it until it is.
My Blog