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 results.XX, results.YY
from
(
select F1.ID1, F2.ID2, F1.X as XX, F1.Y as YY, F2.X, F2.Y
from
(select
@rownum1 := @rownum1 + 1 as ID1,
F.X,
F.Y
from (SELECT @rownum1 := 0) as r, Functions as F) as F1,
(select
@rownum2 := @rownum2 + 1 as ID2,
F.X,
F.Y
from (SELECT @rownum2 := 0) as r, Functions as F) as F2
where F1.ID1 != F2.ID2 and F1.X = F2.Y and F1.Y = F2.X
) as results
where results.XX <= results.YY
order by results.XX;
`
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 results.XX, results.YY from ( select F1.ID1, F2.ID2, F1.X as XX, F1.Y as YY, F2.X, F2.Y from (select @rownum1 := @rownum1 + 1 as ID1, F.X, F.Y from (SELECT @rownum1 := 0) as r, Functions as F) as F1, (select @rownum2 := @rownum2 + 1 as ID2, F.X, F.Y from (SELECT @rownum2 := 0) as r, Functions as F) as F2 where F1.ID1 != F2.ID2 and F1.X = F2.Y and F1.Y = F2.X ) as results where results.XX <= results.YY order by results.XX;
`