We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
select distinct
a.x, a.y
from Functions a
inner join functions b
on a.x=b.y and b.x=a.y
where a.x<=a.y
-- to remove self join cases if equal pair (A,A) exist in the table, it will self join so i'll check the result in the base table that (A,A) cases should have atleast 1 entry
and (a.x != a.y
or (
select count(*) from functions
where x=a.x and y=a.y
)>1)
order by a.x
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Symmetric Pairs
You are viewing a single comment's thread. Return to all comments →
select distinct a.x, a.y from Functions a inner join functions b on a.x=b.y and b.x=a.y where a.x<=a.y
-- to remove self join cases if equal pair (A,A) exist in the table, it will self join so i'll check the result in the base table that (A,A) cases should have atleast 1 entry
and (a.x != a.y or ( select count(*) from functions where x=a.x and y=a.y )>1) order by a.x