Symmetric Pairs

  • + 0 comments

    Without using CTEs:-

    SELECT X, Y FROM ( (SELECT FN1.X AS X, FN1.Y AS Y
    FROM FUNCTIONS FN1 JOIN FUNCTIONS FN2 ON FN1.X = FN2.Y AND FN1.Y = FN2.X
    AND FN1.X <> FN1.Y AND FN1.X <= FN1.Y ) UNION (SELECT FN3.X AS X, FN3.Y AS Y FROM FUNCTIONS FN3 WHERE FN3.X = FN3.Y GROUP BY FN3.X, FN3.Y HAVING COUNT(*) > 1 ) ) ALIAS ORDER BY X