Finding Duplicates with SQL

Here’s query for finding duplicates in a table. Suppose you want to find all Usernames values in a table that exist more than once:

SELECT Username, COUNT(Username) AS NumOccurrences
FROM   Users
GROUP BY Username
HAVING      (COUNT(Username) > 1)

Deixe uma resposta

O seu endereço de email não será publicado. Campos obrigatórios marcados com *