?
Solved

How to find duplicates in SQL Server

Posted on 2016-11-18
3
Medium Priority
?
61 Views
Last Modified: 2016-11-18
Hi guys,

I want to find duplicate records from SQL Server, however i want to include the ID field as well which is unique. For example
1 a b c d
2 a b c d
3 a b c d
4 g h i j

Open in new window

how write a query to find first three records along with their ids.

regards
0
Comment
Question by:shah36
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 29

Expert Comment

by:Pawan Kumar
ID: 41892688
Try..

SELECT id, Col1,col2,col3,col4 FROM 
(
SELECT * , ROW_NUMBER() OVER (PARTITION BY COL1,COL2,COL3,col4 ORDER BY (SELECT 1)) rnk
FROM yourTable
)k
WHERE rnk > 1

Open in new window

0
 
LVL 49

Accepted Solution

by:
PortletPaul earned 2000 total points
ID: 41892691
Try using count() over()

select * from (
Select *
, count(*) over(partition by col1,col2,col3,col4) as counted
From that_table) d
Where counted > 1
0
 

Author Closing Comment

by:shah36
ID: 41892703
Thanks a lot for your help. yes it worked like a magic
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A couple of weeks ago, my client requested me to implement a SSIS package that allows them to download their files from a FTP server and archives them. Microsoft SSIS is the powerful tool which allows us to proceed multiple files at same time even w…
I have a large data set and a SSIS package. How can I load this file in multi threading?
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.
Suggested Courses

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question