我有三个表我需要查询表1,2和3并分别从表1中选择C1,从表2和3中选择C2,以便它给出结果。有没有办法得到这个?
答案 0 :(得分:4)
是:
select t1.c1, coalesce(t2.c2, t3.c2) c2
from Table1 t1
left join Table2 t2 on t1.c1 = t2.c1
left join Table3 t3 on t1.c1 = t3.c1
答案 1 :(得分:1)
尝试以下方法:
SELECT T1.C1, T2.C2
FROM T1
INNER JOIN T1.C1 = T2.C1
UNION ALL
SELECT T1.C1, T3.C2
FROM T1
INNER JOIN T1.C1 = T3.C1