-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
Nuñito Calzada
  • 4,394
  • 47
  • 174
  • 301

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,242,037
  • 58
  • 646
  • 786
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
  • 42,561
  • 8
  • 45
  • 63