How to find duplicate values in SQL Server
Posted
by hgulyan
on Stack Overflow
See other posts from Stack Overflow
or by hgulyan
Published on 2010-05-20T09:30:15Z
Indexed on
2010/05/20
10:50 UTC
Read the original article
Hit count: 263
Hi,
I'm using SQL Server 2008. I have a table
Customers
customer_number int
field1 varchar
field2 varchar
field3 varchar
field4 varchar
... and a lot more columns, that doesn't matter for my queries.
Column *customer_number* is pk. I'm trying to find duplicate values and some differences between them.
Please, help me to find all rows that have same
1) field1, field2, field3, field4
2) only 3 columns are equal and one of them isn't (except rows from list 1)
3) only 2 columns equal and two of them aren't (except rows from list 1 and list 2)
In the end, I'll have 3 tables with this results and additional groupId, which will be same for a group of similars (For example, for 3 column equals, rows that have 3 same columns equal will be a seperate group)
Thank you.
© Stack Overflow or respective owner