Delete All But Last Record 1 to Many Table
suggest changeDeleting from a CTE is SQL Server syntax.
WITH cte AS (
SELECT ProjectID,
ROW_NUMBER() OVER (PARTITION BY ProjectID ORDER BY InsertDate DESC) AS rn
FROM ProjectNotes
)
DELETE FROM cte WHERE rn > 1;
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents