SQL Server - Delete all non distinct rows
;WITH PartitionedData AS ( SELECT itemid, fieldid, version, ROW_NUMBER() OVER(PARTITION BY ItemId ORDER BY version DESC) AS 'RowNum' FROM dbo.VersionedFields ) DELETE FROM PartitionedData WHERE RowNum > 1
Published at 9 Dec 2015, 09:00 AM
Tags: SQL