Mysql
 sql >> Datenbank >  >> RDS >> Mysql

Doppelte Datensätze zurückgeben

SELECT col1, col2, col3, col4
     , COUNT(*) AS cnt
FROM yourTable
GROUP BY col1, col2, col3, col4
HAVING COUNT(*) > 1

Wenn Sie weitere Spalten anzeigen möchten, können Sie JOIN werden das Obige zur Tabelle:

SELECT t.*
     , dup.cnt
FROM yourTable t
    JOIN
      ( SELECT col1, col2, col3, col4
             , COUNT(*) AS cnt
        FROM yourTable
        GROUP BY col1, col2, col3, col4
        HAVING COUNT(*) > 1
      ) AS dup
      ON  t.col1 = dup.col1
      AND t.col2 = dup.col2
      AND t.col3 = dup.col3
      AND t.col4 = dup.col4