Oracle SQL添加左连接相同的表

时间:2014-09-12 06:18:50

标签: sql oracle join

工作来源

SELECT T1.ref, T2.rtiers , T3.nom1
FROM T1, T2, T3 
WHERE T2.code = T1.rempl AND T3.code = T1.rtiers

请帮助使用正确的语法将相同的表添加到现有联接中:

not working
SELECT T1.ref, T2.rtiers, T3.nom1, N.nom1
FROM T1, T2, T3 
WHERE T2.code = T1.rempl 
    AND T3.code = T1.rtiers 
    AND T3.alias=T2.rtiers(+) AS N

not working
SELECT T1.ref, T2.rtiers, T3.nom1, N.nom1
FROM T1, T2, T3, (LEFT JOIN T3 ON T3.alias=T2.rtiers) N
WHERE T2.code = T1.rempl 
    AND T3.code = T1.rtiers

1 个答案:

答案 0 :(得分:0)

像这样:

SELECT T1.ref, T2.rtiers , T3.nom1, N.nom1 as nom1_outer
FROM T1, T2, T3, T3 N
WHERE T2.code = T1.rempl 
AND T3.code = T1.rtiers
AND N.alias(+) = T2.rtiers

或更好

SELECT T1.ref, T2.rtiers , T3.nom1, N.nom1 as nom1_outer
FROM T1
JOIN T2 ON T2.code = T1.rempl 
JOIN T3 ON T3.code = T1.rtiers 
LEFT JOIN T3 N ON N.alias = T2.rtiers