答案 0 :(得分:5)
只需使用LEFT JOIN
,然后选择如下所示的字段
select t.id, tt.tid, ot.oid, pt.pid
from test t
left join test_tid tt on t.id = tt.id
left join test_pid pt on t.id = pt.id
left join test_oid ot on t.id = ot.id
答案 1 :(得分:0)
试试这个:
select isnull(isnull(t1.id,t2.id),t3.id),t1.tid,t2.oid,t3.pid
from test_tid t1 full outer join test_oid t2
on (t1.id = t2.id)
full outer join test_pid t3
on (t1.id = t3.id)