Skip to content

Instantly share code, notes, and snippets.

@codez0mb1e
Last active November 27, 2021 18:25
Show Gist options
  • Save codez0mb1e/eb691183bd177300ac4e0c142b7406b0 to your computer and use it in GitHub Desktop.
Save codez0mb1e/eb691183bd177300ac4e0c142b7406b0 to your computer and use it in GitHub Desktop.
Delete duplicates from table
WITH duplicates AS (
SELECT
*,
ROW_NUMBER() OVER (
PARTITION BY Id
ORDER BY [Timestamp]
) row_n
FROM
<table_name> -- NOTE: insert name of target table here
WHERE
DATEDIFF(month, [Timestamp], GETDATE()) = 1
)
DELETE FROM duplicates
WHERE row_n > 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment