SQL Full Outer Join on same column in same table

后端 未结 1 708
太阳男子
太阳男子 2021-01-23 07:27

This may be more of a design issue than anything, but I\'m hoping it\'s possible without too much voodoo.

Suppose I have a table like this:

SELECT * FROM         


        
相关标签:
1条回答
  • 2021-01-23 08:00

    You're doing the wrong thing first, and attempting to fix it up afterwards. That's not going to work.

    The things you want to join are select * from stuff where grp = 'a' and select * from stuff where grp = 'b'. So join those:

    select a.ID as a, b.ID as b from
      (select * from stuff where grp = 'a') a
    full join
      (select * from stuff where grp = 'b') b
    on b.id = a.id
    

    SQL Fiddle

    0 讨论(0)
提交回复
热议问题