Now that I’m back, here is the code I was recommending:
with normalized as (
(select id1 as this_id, id2 as that_id from myTABLE)
UNION
(select id2 as this_id, id1 as that_id from myTABLE)
)
select
that_id
from
normalized
where
this_id = 'xyz'
nor was I… I just disagree that your solution is cleaner than mine. the CASE is just a replacement for the one field in a single select statement, where yours would require the select logic be duplicated, and/or another level of sub query.
SELECT
CASE id1
WHEN 'xyz' THEN id2
ELSE id1
END AS newID
WHERE id1='xyz' OR id2='xyz'
-- If id1 and id2 are indexed this is very fast, without this "where" all the DB will be scanned