Real reason why Left outer JOIN only you need to use in DB2 SQL

The story of JOINS in SQL is to get data from many tables. Actually in DB2 there are both LEFT and RIGHT outer JOINS present.

There is no difference between a left outer join and right outer join other than where the starting driver is coded

LEFT JOIN


SELECT D.DEPTNO, D.DEPTNAME, D.MGRNO,
E.LASTNAME
FROM DEPT D LEFT JOIN
EMP E ON D.MGRNO = E.EMPNO

Right 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 is left side one. When you give RIGHT join, then the drive table is right side one.

  • DB2 itself converts RIGHT JOIN into LEFT JOIN during query processing
  • Main thing is, to avoid confusion, always code LEFT OUTER join

Also read

Advertisements

Author: Srini

Experienced software developer. Skills in Development, Coding, Testing and Debugging. Good Data analytic skills (Data Warehousing and BI). Also skills in Mainframe.