You are on page 1of 1

Here's a handy query for finding duplicates in a table.

Suppose you want to find all email addresses in a table that exist more than once: SELECT email, COUNT(email) AS NumOccurrences FROM users GROUP BY email HAVING ( COUNT(email) > 1 ) You could also use this technique to find rows that occur exactly once: SELECT email FROM users GROUP BY email HAVING ( COUNT(email) = 1 ) delete LMIGLIONICO.ZLARRY_DIVIDEND t where t.client_id in (SELECT t.CLIENT_ID FROM LMIGLIONICO.ZLARRY_DIVIDEND t GROUP BY t.client_id HAVING ( COUNT(t.client_id) > 1 )) and t.address_type_code = 'OFFICE'; select substr(t.first_name,1,4)||t.last_name USERID, count (substr(t.first_name,1,4)||t.last_name) as NumOccurrences from zcurrent_insureds_view t group by substr(t.first_name,1,4)||t.last_name having (count(substr(t.first_name,1,4)||t.last_name) > 1);

You might also like