Finding duplicate records in tables

I have a table with some duplicate records in them

Can someone please suggest the best or most efficient way of quickly finding out duplicates in a table & print those records out.
Jay RAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Vitor MontalvãoMSSQL Senior EngineerCommented:
Which fields should we query to know that the record is duplicated (ID, name, ...)?
0
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
Here's a code and image-heavy tutorial on identifying and deleting duplicate rows in SQL Server ... SQL Server Delete Duplicate Rows Solutions

If you have any needs that this article doesn't cover, then you're going to have to provide a more detailed question.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Leo TorresSQL DeveloperCommented:
Try This

col1 and col2 are the columns you are looking for dups in. It could be 1 or 2 or more. Somedate does not have to be a date just something you can order by.
You have to decide

Select * from (
Select *,
Row_Number() Over (Partition by Col1,Col2 Order BY SomeDate) rn
from dbo.MyTable
) a
Where a.rn >1

Open in new window

0
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
btw I see this is your first week here, so welcome to EE.
0
Tapan PattanaikSenior EngineerCommented:
HI Jay,

For example, If you want to check duplicate Email in one of the column in a table

SELECT email,
 COUNT(email) AS NumOccurrences
FROM users
GROUP BY email
HAVING ( COUNT(email) > 1 )
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server 2008

From novice to tech pro — start learning today.