Finding duplicates with SQL


/ Published in: SQL
Save to your folder(s)

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


Copy this code and paste it in your HTML
  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 )

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.