The problem with your query is that the subquery goes in details to find records with a sequence number less than the maximum. And then he selects everything with the same request - which will include the maximum order number.
I prefer to fix this with CTE as follows:
with toupdate as ( select t.*, MAX(OrderNumber) as MaxON from Workflow_txn where RequestId = 3 ) UPDATE toupdate SET Status = 1 where OrderNumber < MaxON;
I like this structure because I can run CTE separately to see which records are likely to be updated.
To correct your request, you must change the request to use OrderNumber and repeat RequestId = 3 :
UPDATE Workflow_Txn SET Status = 1 WHERE [RequestId] = 3 and OrderNumber in ( SELECT [OrderNumber] FROM Workflow_Txn WHERE [OrderNumber] < (SELECT MAX(OrderNumber) FROM Workflow_Txn WHERE RequestId = 3) AND RequestId = 3 )
Gordon linoff
source share