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.
- Prepare
- SQL
- Advanced Join
- Symmetric Pairs
- Discussions
Symmetric Pairs
Symmetric Pairs
Sort by
recency
|
1350 Discussions
|
Please Login in order to post a comment
with cte as ( select row_number() over ( order by x) id, * from Functions ) select distinct t.x,t.y from cte t join cte t1 on t.x = t1.y and t.y = t1.x and t1.id <> t.id where t.x<=t.y order by 1 asc
Check out the complete video solution here - https://www.youtube.com/watch?v=kjXGAypRuuE&t=381s
SELECT LEAST(f1.X, f1.Y) AS X1, GREATEST(f1.X, f1.Y) AS Y1 FROM Functions f1 JOIN Functions f2 ON f1.X = f2.Y AND f1.Y = f2.X WHERE f1.X <= f1.Y ORDER BY X1, Y1;
with t1 as (select least(x,y) as x1,greatest(x,y) as y1 from functions ), t2 as (select greatest(x,y) as x2,least(x,y) as y2 from functions ), t3 as ( select x1,y1,x2,y2 from t1,t2 where x1=y2 and y1=x2 ), t4 as (select x1,y1 from t3 where x11 order by x1 ;
SELECT F1.X ,F1.Y FROM Functions F1 JOIN Functions F2 ON F1.X = F2.Y AND F1.Y = F2.X WHERE F1.X <= F1.Y ORDER BY F1.X;
TEST CASE FAILED !
CAN ANYONE PLEASE CORRECT THE ABOVE CODE PLEASE