select table1.id, table1.x, table1.y
from yourtable table1
where exists (select x, y
from yourtable table2
where table1.x=table2.y and table1.y=table2.x)
Union
select t1.x, t1.y
from yourtable t1
where exists (select x, y
from yourtable t2
where t1.x=t2.y and t1.x=t2.y)
and t1.x<t1.y
Please don't copy paste the code directly.I believe there is some syntactical issue.First resolve that and then the main logic will be with"and" "or" operators.
I have tested this solution for the second query after union in sql fiddle.Please vote it will indeed help the community.
SQL Fiddle[
^]