Symmetric Pairs

  • + 0 comments
    WITH _cte_functions_rules AS (
        SELECT * FROM (
            SELECT x, y, count(1) AS xy_count FROM Functions GROUP BY x, y
        ) a WHERE x <> y OR xy_count > 1
    )
    SELECT least(f1.x, f1.y) AS x, greatest(f1.y, f1.x) AS f
      FROM _cte_functions_rules f1
      JOIN _cte_functions_rules f2
        ON f2.y = f1.x
       AND f2.x = f1.y
     GROUP BY 1,2
     ORDER BY x