How to find duplicate values in SQL Server
- by hgulyan
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.