-1

All,

I am currently trying to catch instances where a user made a change, but then the user went back and reverted the change. As you can see in the picture below I need to catch rows where the ID is the same and then the value1 from the first record matches the value2 from the second record and the value1 from the first record matches the value2 from the first record. I am not sure this is the best way to approach this, but this is what came to mind. I tried separating via sub query, but no luck on that.

Sample Table

  • Per SO guidelines please include data as text not images and include any code you've tried as well. – Reeza Jun 04 '21 at 20:41

2 Answers2

0

You can get these rows using exists:

select t.*
from t
where exists (select 1
              from t t2
              where t2.id = t.id and
                    t2.value1 = t.value2 and
                    t2.value2 = t.value1
             );
Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786
0

You may use this:

SELECT ID, Value1, Value2
From mytable a
INNER JOIN mytable b ON b.ID = a.ID and b.Value1 = Value2
joserobertog
  • 109
  • 4