Symmetric Pairs

  • + 0 comments

    MySQL

    SELECT DISTINCT f.x, f.y
    FROM (SELECT x, y, 
          ROW_NUMBER() OVER (ORDER BY x ASC) AS id
          FROM Functions) AS f
    INNER JOIN (SELECT x, y, 
                ROW_NUMBER() OVER (ORDER BY x ASC) AS id
                FROM Functions) AS f2 ON f.x = f2.y
    WHERE f.x <= f.y AND f2.x = f.y AND f.id != f2.id
    ORDER BY f.x