asmgx
asmgx

Reputation: 7984

Double outer Join

I have table A that looks like this

ID     AValue
----------------------
3      Tom
5      John
9      Mike

and table B that looks like this

ID     BValue
----------------------
2      Nancy
3      Maria
9      Clara
10     Sophia

I am trying to join both tables to get this result

ID      AValue         BValue
------------------------------
2       <NULL>         Nancy
3       Tom            Maria
5       John           <NULL>
9       Mike           Clara   
10      <NULL>         Sophia

If i try to left outer join I would miss the records that do not have match in A and If I try the right outer join i would miss the records that do not have match in B

any other way I can use?

Upvotes: 0

Views: 43

Answers (1)

Squirrel
Squirrel

Reputation: 24763

what you need is FULL OUTER JOIN

SELECT ID = coalesce(a.ID, b.ID), AValue, BVlaue
FROM   TalbleA a FULL OUTER JOIN TableB b
       ON a.ID = b.ID

Upvotes: 3

Related Questions