SQL: doppelte Datensätze finden

Will man auf einer Tabelle in nachhinein  einen Key über mehrere Felder anlegen, scheitert das machmal an doppelten Datensätzen. Mit folgendem Schnippsel kann man doppelte Datensätze finden:

Hier ein Beispiel für eine Zelle

SELECT domain, COUNT(domain) AS NumOccurrences
FROM domains
GROUP BY domain
HAVING ( COUNT(domain) > 1 )

Hier ein Beispiel für einen Schlüssel über mehrere Zellen:

SELECT domain, subdomain, email, COUNT(domain) AS NumOccurrences
FROM domains
GROUP BY domain, subdomain, email
HAVING ( COUNT(domain) > 1 and COUNT(subdomain) > 1 and COUNT(email) > 1)

Related Posts:

  • No Related Posts