[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

How to find duplicates in SQL Server

Posted on 2016-11-18
3
Medium Priority
?
66 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 32

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

These days, all we hear about hacktivists took down so and so websites and retrieved thousands of user’s data. One of the techniques to get unauthorized access to database is by performing SQL injection. This article is quite lengthy which gives bas…
One of the most important things in an application is the query performance. This article intends to give you good tips to improve the performance of your queries.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

656 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