Remove Duplicate Rows from a SQL Table

Remove Duplicate Rows from a SQL Table

A small reminder for myself:


delete t from
(
SELECT *
, DupRank = ROW_NUMBER() OVER (
              PARTITION BY PurchaseOrderNumber, LineNumber
              ORDER BY (SELECT NULL)
            )
FROM [PurchaseOrderLines]
) as t
where DupRank > 1

Leave a Reply

Your email address will not be published. Required fields are marked *