Click here to Skip to main content
Click here to Skip to main content

Tagged as

Find duplicate values in SQL Server

, 13 Oct 2011
Rate this:
Please Sign up or sign in to vote.
How to find duplicate values in SQL Server.

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 )

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

aspnet -i
Web Developer
India India
Software developer by profession, working for a service and product based organisation in India.
 
Career graph:
Software Programmer since 2002.
Web Developer in ASP.NET since 2004.
 
Interests:
I love reading the blogs and articles of technology experts. I love codeproject and stackoverflow .
 
I love to share knowledge and help the programmers. I appreciate if some body corrects my code or my concepts which helps me learn.

Comments and Discussions

 
GeneralMy vote of 1 Pinmemberdkboss20-Jul-12 1:02 
GeneralRe: My vote of 1 Pinmemberaspnet_regiis20-Jul-12 1:07 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web04 | 2.8.140827.1 | Last Updated 13 Oct 2011
Article Copyright 2011 by aspnet -i
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid