Last active
February 15, 2022 11:05
-
-
Save 6ui11em/cbcfa585c231aad64e8a8092c6ddc3dd to your computer and use it in GitHub Desktop.
SQL: Find duplicate values #mysql #sql #select #duplicate
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 | |
col, | |
COUNT(col) | |
FROM | |
table_name | |
GROUP BY col | |
HAVING COUNT(col) > 1; | |
--- | |
SELECT | |
col1, COUNT(col1), | |
col2, COUNT(col2), | |
... | |
FROM | |
table_name | |
GROUP BY | |
col1, | |
col2, ... | |
HAVING | |
(COUNT(col1) > 1) AND | |
(COUNT(col2) > 1) AND | |
... | |
--- | |
-- Get duplicates with column and row values | |
select s.id, t.* | |
from [stuff] s | |
join ( | |
select name, city, count(*) as qty | |
from [stuff] | |
group by name, city | |
having count(*) > 1 | |
) t on s.name = t.name and s.city = t.city |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment