The concept of JOINS in SQL is to get data from multiple Tables. In DB2, you can find two types of outer joins – LEFT outer and RIGHT outer JOINS.
There is no difference between a left outer join and right outer join other than where the starting driver table is coded
LEFT Outer JOIN
SELECT D.DEPTNO, D.DEPTNAME, D.MGRNO, E.LASTNAME FROM DEPT D LEFT JOIN EMP E ON D.MGRNO = E.EMPNO
Right Outer JOIN
SELECT D.DEPTNO, D.DEPTNAME, D.MGRNO, E.LASTNAME FROM EMP E RIGHT JOIN DEPT D ON D.MGRNO = E.EMPNO
When you give LEFT join, the driver table will be left side one. When you give RIGHT join, then the driver table will be right side one.
LEFT outer Join is Better Why
- DB2 itself converts RIGHT outer JOIN into LEFT outer JOIN during SQL query processing
- So to avoid confusion and save CPU time always code only LEFT OUTER join
- This improves your SQL query performance