Sql query to compare where rows have the same value in different columns
Posted on 2014-04-02
Have a sample table as follows:
ID Old New
123 a b
123 b a
456 a b
456 b c
Would like to write a query to select where an ID has the same Old value as it does a New value.
Basically, looking for where the old value was changed and then changed back to the current value, and what those 2 values would be.
So the result set I want back is:
ID Old New Newest
123 a b a
I would not want to get any of the 456 IDs back because that went from a to b to c, not back to a again.
Hope this is enough information.