SQL: Find duplicated records

Example of how to find duplicated firstname and lastname [PostgresSQL]:

DROP VIEW contact_duplicates;
CREATE OR REPLACE VIEW contact_duplicates AS 
 SELECT count(*) AS count, contacts.firstname, 
 contacts.lastname
 FROM contacts
 GROUP BY contacts.firstname, contacts.lastname
 HAVING count(*) > 1;

Leave a comment