Suppose I have two different ID’s assigned for same record. For example
RecordID | ID1 | ID2 -------------------- 1 | X | A 2 | X | B 3 | Y | C 4 | Y | C 5 | Y | D 6 | Z | E 7 | Z | E
Now, I want to get the records where ID1 is assigned to the same value where as ID2 is assigned to a different value.
For example, I want to get:
1, X, A
2, X, B
Here ID1 assigned it X where as ID2 assigned it A and B, two different values.
Is it possible to write a query in SQL or SQL server that will return such records?
You need to use a subquery where, for each row, you poke through the table and see if any other rows match a certain criteria related to it.
pseudo sql: