Posted By

jmiller on 02/25/10


Tagged

sql count find duplicates


Versions (?)

Who likes this?

3 people have marked this snippet as a favorite

andyhartleeds
roakin
Tyster


Finding duplicates with SQL


 / Published in: SQL
 

URL: http://www.petefreitag.com/item/169.cfm

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

  1. # Suppose you want to find all email addresses in a table that exist more than once:
  2.  
  3. SELECT email,
  4. COUNT(email) AS count
  5. FROM users
  6. GROUP BY email
  7. HAVING ( COUNT(email) > 1 )
  8.  
  9.  
  10. # You could also use this technique to find rows that occur exactly once:
  11.  
  12. SELECT email
  13. FROM users
  14. GROUP BY email
  15. HAVING ( COUNT(email) = 1 )

Report this snippet  

You need to login to post a comment.