Created
April 24, 2019 20:45
-
-
Save imsoftware/5b8d794c1aa5a64eb55afd6dd738dc42 to your computer and use it in GitHub Desktop.
sql find duplicates
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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