I would like to convert the following Oracle SQL query syntax (Use LEFT OUTER JOIN
instead of (+)
):
SELECT *
FROM TABLEA A, TABLEB B, TABLEC C, TABLED D
WHERE MY_COL = @col_val
AND A.X = B.X(+)
AND B.Y = C.Y(+)
AND D.Z=A.Z
Here is what I tried so far:
SELECT *
FROM TABLEA A, TABLEB B, TABLEC C, TABLED D
LEFT OUTER JOIN TABLEA A ON A.X = B.X
LEFT OUTER JOIN TABLEC C ON B.Y = C.Y
WHERE MY_COL = @col_val
AND D.Z = A.Z;
But I get the error :
"ORA-00904: "B"."X" : invalid identifier"
The join
on D
is an inner join, the rest are left outer joins:
SELECT *
FROM TABLEA A JOIN
TABLED D
ON D.Z = A.Z LEFT JOIN
TABLEB B
ON A.X = B.X LEFT JOIN
TABLEC C
ON B.Y = C.Y
WHERE MY_COL = @col_val;
I always start chains of joins with inner joins followed by the left outer join
. I never use right join
, and full join
rather rarely. The inner joins define the rows in the result set, so they come first.
You don't should mix explicit and implicit sintax
SELECT *
FROM TABLEA A
INNER JOIN TABLEL L ON L.Z = A.Z
LEFT OUTER JOIN TABLEB B ON A.X = B.X
LEFT OUTER JOIN TABLEC C ON B.Y = C.Y
WHERE A.MY_COL = @col_val
you should use inner join (or join) for TABLEL
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With