Symmetric Pairs

  • + 13 comments

    My solution:

    select x, y from functions f1 
        where exists(select * from functions f2 where f2.y=f1.x 
        and f2.x=f1.y and f2.x>f1.x) and (x!=y) 
    union 
    select x, y from functions f1 where x=y and 
        ((select count(*) from functions where x=f1.x and y=f1.x)>1)    
            order by x;