[英]SQL join on second table all distinct rows showing a column from both tables
您正在寻找full join
:
select id, a.col1, b.col2
from a full join
b
using (id);
如果您的数据库不支持full join
,我建议:
select a.id, a.col1, b.col2
from a left join
b
on a.id = b.id
union all
select b.id, null, b.col2
from b
where not exists (select 1 from a where a.id = b.id);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.