Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

How to find duplicate row in a table - MSSQL

DZone's Guide to

How to find duplicate row in a table - MSSQL

· Database Zone
Free Resource

Learn how to move from MongoDB to Couchbase Server for consistent high performance in distributed environments at any scale.

The below given query will fetch the duplicate rows in MSSQL with number of occurance of each row.

SELECT     <all column names - comma seperated>, COUNT(<name of any one column>) AS Occurance_Count
FROM <table name>
GROUP BY <all column names - comma seperated>
HAVING (COUNT(<name of any one column>) > 1)

 

Note: The data in '<>' should be replaced with relevent data. E.g. '<all column names - comma seperated>' should be replaced with 'a,b,c' where a, b and c are the names of the columns in the table.

Want to deliver a whole new level of customer experience? Learn how to make your move from MongoDB to Couchbase Server.

Topics:

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}