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
|
1524 Discussions
|
Please Login in order to post a comment
the question is incorrect for case where we have the following input: 20 21 21 20 20 21 21 20 in this case 20 21 should be printed twice applying distinct while selecting the rows will only print 20 21 once
SELECT f1.x, f1.y FROM functions f1 JOIN functions f2 ON f1.x = f2.y AND f2.x = f1.y WHERE f1.x < f1.y
UNION
SELECT x, y FROM functions GROUP BY x, y HAVING x = y AND COUNT(*) > 1
ORDER BY x, y;