Skip to content Skip to sidebar Skip to footer

Delete Where Both Columns Match

I have two tables Person (contain oldest date (farthest in future) when person moved OR WILL moved to another address) ID OLDESTADDRESSMOVEDATE 1

Solution 1:

You can query using row_number, cte and delete

;WITH cte AS
(
    SELECT *, RowN = ROW_NUMBER() OVER (PARTITION BY ID ORDER BY AddressMoveDate DESC) FROM Address
)
DELETE FROM cte WHERE RowN > 1

Post a Comment for "Delete Where Both Columns Match"