PostgreSQL: Find and count duplicate entries in a table
SELECT
*
FROM
(
SELECT
COUNT(substr(tmp.*::text, strpos(tmp.*::text, ','))) AS duplicate_count,
substr(tmp.*::text, strpos(tmp.*::text, ',')) AS duplicate_entry
FROM
my_table AS tmp
GROUP BY duplicate_entry
)
AS subquery
WHERE duplicate_count > 1
GROUP BY duplicate_count, duplicate_entry
Url: http://sklueh.de/2012/09/pgsql-duplikate-in-einer-tabelle-finden/
Language: SQL | User: sklueh | Created: Sep 24, 2013