2 Simple SQL Queries on Self-join and Inner Join

SELECT PROJNO,EMPNO,LASTNAME,DEPTNAME

FROM  (TEST.EMP E  JOIN
                 TEST.DEPT  D

ON        D.DEPTNO = E.WORKDEPT)  JOIN
              TEST.PROJ. P

ON        EMPNO = RESPEMP;

The above is the best example for finding match in 3 tables using Inner join.

SELECT A.DEPTNO,A.DEPTNAME,A.ADMRDEPT,A.DEPTNAME

FROM TEST.DEPT A

             TEST.DEPT B

WHERE A.ADMRDEPT =A.DEPTNO;

The above SQL query is the best example for self join.

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.