Click here to Skip to main content
13,044,705 members (61,443 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as

Stats

39K views
1 bookmarked
Posted 13 Oct 2011

Find duplicate values in SQL Server

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

Balaji Birajdar (India)
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.

You may also be interested in...

Pro

Comments and Discussions

 
GeneralMy vote of 4 Pin
Umesh AP3-May-16 3:00
memberUmesh AP3-May-16 3:00 
GeneralMy vote of 1 Pin
dkboss20-Jul-12 1:02
memberdkboss20-Jul-12 1:02 
GeneralRe: My vote of 1 Pin
aspnet_regiis20-Jul-12 1:07
memberaspnet_regiis20-Jul-12 1:07 

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

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

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.170713.1 | Last Updated 13 Oct 2011
Article Copyright 2011 by Balaji Birajdar (India)
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid