SQL三表联合查询(有NULL记录)

2024-12-19 04:38:14
推荐回答(3个)
回答1:

外连接既可
select a.*,b.*,c.*
from a left outer join b on a.id=b.id
left outer c on a.id =c.id

你好歹把连接条件改改啊:
select t1.id,t1.name,t2.ca,t3.hi
from t1 left outer join t2 on t1.id=t2.t1_id
left outer t3 on t1.id =t3.t1_id and t2.id = t3.t2_id

回答2:

在查询条件後面加一个条件
and t2_id<>null

回答3:

select t1.id,t1.name,t2.ca,t3.hi
from t3 left outer join
t2 on t3.t2_id=t2.id left outer join
t1 on t1.id=t2.t1_id and t1.id=t3.t1_id