Run the first query and see if the NewStatus is what you want to set the status to. If (AND ONLY IF) you are satisfied that that is the right thing, then run the second query;with cte as( select *, row_number() over(partition by CustId order by ID desc) as RN from YourTable)select *, case when RN = 1 then 'Y' else 'N' end as NewStatus; from cte;;with cte as( select *, row_number() over(partition by CustId order by ID desc) as RN from YourTable)update cte set status = case when RN = 1 then 'Y' else 'N' end;