I have a table like
+ ----------------------- +
| RowID | FromCol | toCol |
+ ----------------------- +
| 1 | a | b |
| 2 | b | c |
| 3 | c | d |
| 4 | c | b |
| 5 | b | a |
+ ----------------------- +
I would like to remove the rows that has FromCol –> ToCol same value as ToCol –> FromCol
For eg. RowID 1 is a–>b and RowID 5 has b–>a so rowID 5 should be removed. Similarly RowID 4 should be removed because it has a swapped value like RowID 2.
My expected result Table is:
+ ----------------------- +
| RowID | FromCol | toCol |
+ ----------------------- +
| 1 | a | b |
| 2 | b | c |
| 3 | c | d |
+ ----------------------- +
I want to get this as a View preferably with CTE NOT using SQL CURSOR.
Can anybody help me please.
Thanks
Very similar to @Barmar, but using a subquery instead of an inline table.
This works in SQL Server