-2

I have

T1: USER_ID OSX
       1     Y
       2     Y  

T2: USER_ID ANDROID
       1     Y
       3     Y  

I want to join the tables as follows but i don't know how

T3: USER_ID ANDROID  OSX
       1     Y        Y
       2     null     Y
       3     Y        null
Nunyet de Can Calçada
  • 4,171
  • 41
  • 153
  • 252

2 Answers2

2

You want a full outer join:

select coalesce(t1.user_id, t2.user_id) as user_id,
       t2.android, t1.osx
from t1 full join
     t2
     on t1.user_id = t2.user_id;
Gordon Linoff
  • 1,198,228
  • 53
  • 572
  • 709
0

Use full join, better handle null values:

select coalesce(t1.user_id, t2.user_id) as user_id,
       coalesce(t2.android,'N/A') as android,
       coalesce(t1.osx,'N/A') as osx
from t1
full join t2 on t1.user_id = t2.user_id
jarlh
  • 40,041
  • 8
  • 39
  • 58