A left exception join returns only the rows from the first table that do not have a match in the second table.
SELECT EMPNO, LASTNAME, PROJNO FROM CORPDATA.EMPLOYEE EXCEPTION JOIN CORPDATA.PROJECT ON EMPNO = RESPEMP WHERE LASTNAME > 'S'
This join returns the output:
EMPNO | LASTNAME | PROJNO |
---|---|---|
000170 | YOSHIMURA | - |
000180 | SCOUTTEN | - |
000190 | WALKER | - |
000280 | SCHNEIDER | - |
000300 | SMITH | - |
000310 | SETRIGHT | - |
200170 | YAMAMOTO | - |
200280 | SCHWARTZ | - |
200310 | SPRINGER | - |
200330 | WONG | - |
SELECT EMPNO, LASTNAME FROM CORPDATA.EMPLOYEE WHERE LASTNAME > 'S' AND NOT EXISTS (SELECT * FROM CORPDATA.PROJECT WHERE EMPNO = RESPEMP)
The only difference in this query is that it cannot return values from the PROJECT table.
There is a right exception join, too, that works just like a left exception join but with the tables reversed.