Skip to content

Instantly share code, notes, and snippets.

@imsoftware
Created April 24, 2019 20:45
Show Gist options
  • Select an option

  • Save imsoftware/5b8d794c1aa5a64eb55afd6dd738dc42 to your computer and use it in GitHub Desktop.

Select an option

Save imsoftware/5b8d794c1aa5a64eb55afd6dd738dc42 to your computer and use it in GitHub Desktop.
sql find duplicates
SELECT tablename.colname
FROM tablename
INNER JOIN (
SELECT colname
FROM tablename
GROUP BY colname
HAVING COUNT(db_pid) > 1
)
dup ON tablename.colname = dup.colname
-- e.g.:
SELECT dbs1.a_id
FROM dbs1
INNER JOIN (
SELECT a_id
FROM dbs1
GROUP BY a_id
HAVING COUNT(db_pid) > 1
)
dup ON dbs1.a_id = dup.a_id
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment