Reputation: 709
I have a table that contains two columns.
in the first two rows the values for the columns are reversed, how would I select one record for every instance where one STATION_1_I equals another records STATION_2_I and its STATION_2_I equals STATION_1_I.
Upvotes: 1
Views: 1573
Reputation: 4511
select a,b from
(
select
(case when a<b then a else b end) as a,
(case when a>b then a else b end) as b
from (
select station_1_I as a, station_2_I as b from MyTable
union all
select station_2_I, station_1_I from MyTable
) having count(*)=2 group by a,b
) group by a,b
Upvotes: 2