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
|
1562 Discussions
|
Please Login in order to post a comment
Select a.x,a.y from Functions a inner join Functions b on a.x=b.y and a.y=b.x where a.x
UNION
SELECT x, y FROM Functions WHERE x = y GROUP BY x, y HAVING COUNT(*) > 1 ORDER BY x;
SELECT f1.X, f1.Y FROM Functions f1 INNER JOIN Functions f2 ON f1.X = f2.Y AND f1.Y = f2.X WHERE f1.X <= f1.Y GROUP BY f1.X, f1.Y HAVING COUNT(*) > 1 OR f1.X < f1.Y ORDER BY f1.X;
SELECT f.x,f.y from Functions f inner join Functions f1 on f.X = f1.Y and f.Y = f1.X where f.x <= f.y group by f.x,f.Y having f.x < f.y or (count(f1.x)>1) order by x
with cte as (select * ,row_number() over(order by x ) as r from Functions)
select distinct a.x , a.y from cte a join cte b on a.x=b.y and a.y = b.x and a.r != b.r and a.x <= a.y order by a.x