Wednesday, 28 August 2013

T-SQL - query filtering

T-SQL - query filtering

table1:
Id Customer No_
7044900804 Z0172132
7044900804 Z0194585
7044907735 Z0172222
7044907735 Z0172222
7044910337 Z0172216
7044911903 Z0117392
I would like to get only the values with the same Id AND different
Customer No_ from table1.
Id Customer No_
7044900804 Z0172132
7044900804 Z0194585
I've already tried to use query for finding duplicates, but it won't
filter values with the same Id AND same Customer No_ from table1.
SELECT Id
, [Customer No_]
FROM table1
GROUP BY Id, [Customer No_]
HAVING COUNT(*) > 1
Could you help me with T-SQL query solution? Thanks for all the advices.

No comments:

Post a Comment