Full outer join
Like the left and right outer joins, a full outer join returns matching rows from both tables. However, a full outer join also returns nonmatching rows from both tables.
Suppose that you want to find all employees and all of their projects. You want to see those employees that are not currently in charge of a project as well as any projects that do not have an employee assigned. The following query returns a list of all employees whose names are greater than 'S', along with their assigned project numbers:
SELECT EMPNO, LASTNAME, PROJNO
FROM CORPDATA.EMPLOYEE FULL OUTER JOIN CORPDATA.PROJECT
ON EMPNO = RESPEMP
WHERE LASTNAME > 'S'
Because there are no projects without an assigned employee, the query returns the same rows as a left outer join. Here are the results.
EMPNO | LASTNAME | PROJNO |
---|---|---|
000020 | THOMPSON | PL2100 |
000060 | STERN | MA2110 |
000100 | SPENSER | OP2010 |
000170 | YOSHIMURA | - |
000180 | SCOUTTEN | - |
000190 | WALKER | - |
000250 | SMITH | AD3112 |
000280 | SCHNEIDER | - |
000300 | SMITH | - |
000310 | SETRIGHT | - |
200170 | YAMAMOTO | - |
200280 | SCHWARTZ | - |
200310 | SPRINGER | - |
200330 | WONG | - |