Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert Oracle legacy outer join to Ansi SQL

I have a complex non ansi query and I need to convert in ansi query.

so I will take a small example to describe my problem

input query

 SELECT a.name,
         a.empno,
         b.loc,
         c.inr
    FROM a,
         b,
         c
   WHERE a.deptno = b.deptno(+)
     AND b.empno(+) = 190
     a.deptno = c.deptno(+)
     AND c.empno(+) = 190;

Thanks in advance

like image 547
Kishore Avatar asked Feb 05 '23 15:02

Kishore


1 Answers

Your query is equivalent to the below ANSI compliant query:

SELECT a.name,
       a.empno,
       b.loc,
       c.inr
FROM tab a
LEFT JOIN tab b ON a.deptno = b.deptno AND b.empno = 190
LEFT JOIN tab c ON a.deptno = c.deptno AND c.empno = 190;         

You have to place predicates b.empno = 190 and c.empno = 190 inside the ON clauses of the LEFT JOIN operations, otherwise LEFT JOIN becomes an INNER JOIN.

like image 92
Giorgos Betsos Avatar answered Feb 19 '23 20:02

Giorgos Betsos