• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 89
  • Last Modified:

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.
0
Jay R
Asked:
Jay R
2 Solutions
 
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
 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now