Skip to content

Instantly share code, notes, and snippets.

@brazilnut2000
Created May 1, 2013 20:12
Show Gist options
  • Save brazilnut2000/5497993 to your computer and use it in GitHub Desktop.
Save brazilnut2000/5497993 to your computer and use it in GitHub Desktop.
SQL: Remove duplicate rows that have different ids
-- Source: http://stackoverflow.com/questions/18932/how-can-i-remove-duplicate-rows
DELETE MyTable
FROM MyTable
LEFT OUTER JOIN (
SELECT MIN(RowId) as RowId, Col1, Col2, Col3
FROM MyTable
GROUP BY Col1, Col2, Col3
) as KeepRows ON
MyTable.RowId = KeepRows.RowId
WHERE
KeepRows.RowId IS NULL
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment