Presentation is loading. Please wait.

Presentation is loading. Please wait.

Special Joins Week 4. Objective –Write SELECT statements to display left, right and full outer joins.

Similar presentations


Presentation on theme: "Special Joins Week 4. Objective –Write SELECT statements to display left, right and full outer joins."— Presentation transcript:

1 Special Joins Week 4

2 Objective –Write SELECT statements to display left, right and full outer joins

3 Outer Joins Inner join displays only matching rows Use LEFT OUTER JOIN to display all matching rows and include all unmatched rows from table on left side of JOIN Use RIGHT OUTER JOIN to display all matching rows and include all unmatched rows from table on right side of JOIN Use FULL OUTER JOIN to display all matching rows and include all unmatched rows from both tables

4 Employees Table EMP_ID LAST_NAME DEPT_ID 200 Whalen10 201Hartstein20 202 Fay20 124Mourgos50 141 Rajs 50 142Davies50 143Matos50 144 Vargas50 103Hunold60 104Ernst60 107Lorentz60 149Zlotkey80 174Higgins 80 176 Taylor80 100 King90 101Kochhar90 102De Haan 90 205 Higgins110 206Gietz 110 178 Grant NOTE: Employee 178 not in a dept 20 rows selected.

5 Departments Table DEPARTMENT_ID DEPARTMENT_NAME 10Administration 20Marketing 50Shipping 60IT 80Sales 90Executive 110Accounting 190Contracting NOTE: dept 190 has no employees 8 rows selected.

6 Employees INNER JOIN Departments EMP_ID LAST_NAME DEPT_IDDEPT_NAME 200 Whalen10 Administration 201Hartstein20Marketing 202 Fay20Marketing 124Mourgos50 Shipping 141 Rajs 50Shipping 142Davies50Shipping 143Matos50Shipping 144 Vargas50Shipping 103Hunold60IT 104Ernst60IT 107Lorentz60IT 149Zlotkey80Sales 174Higgins 80Sales 176 Taylor80Sales 100 King90Executive 101Kochhar90Executive 102De Haan 90Executive 205 Higgins110Accounting 206Gietz 110Accounting 19 rows selected.

7 Employees LEFT OUTER JOIN Departments EMP_ID LAST_NAME DEPT_IDDEPT_NAME 200 Whalen10 Administration 201Hartstein20Marketing 202 Fay20Marketing 124Mourgos50 Shipping 141 Rajs 50Shipping 142Davies50Shipping 143Matos50Shipping 144 Vargas50Shipping 103Hunold60IT 104Ernst60IT 107Lorentz60IT 149Zlotkey80Sales 174Higgins 80Sales 176 Taylor80Sales 100 King90Executive 101Kochhar90Executive 102De Haan 90Executive 205 Higgins110Accounting 206Gietz 110Accounting 178Grant 20 rows selected. NOTE: Employee 178 is now displayed!

8 Employees RIGHT OUTER JOIN Departments EMP_ID LAST_NAME DEPT_IDDEPT_NAME 200 Whalen10 Administration 201Hartstein20Marketing 202 Fay20Marketing 124Mourgos50 Shipping 141 Rajs 50Shipping 142Davies50Shipping 143Matos50Shipping 144 Vargas50Shipping 103Hunold60IT 104Ernst60IT 107Lorentz60IT 149Zlotkey80Sales 174Higgins 80Sales 176 Taylor80Sales 100 King90Executive 101Kochhar90Executive 102De Haan 90Executive 205 Higgins110Accounting 206Gietz 110Accounting 190Contracting 20 rows selected. NOTE: Department 190 is now displayed!

9 Employees FULL OUTER JOIN Departments EMP_ID LAST_NAME DEPT_IDDEPT_NAME 200 Whalen10 Administration 201Hartstein20Marketing 202 Fay20Marketing 124Mourgos50 Shipping 141 Rajs 50Shipping 142Davies50Shipping 143Matos50Shipping 144 Vargas50Shipping 103Hunold60IT 104Ernst60IT 107Lorentz60IT 149Zlotkey80Sales 174Higgins 80Sales 176 Taylor80Sales 100 King90Executive 101Kochhar90Executive 102De Haan 90Executive 205 Higgins110Accounting 206Gietz 110Accounting 178Grant 190Contracting 21 rows selected.NOTE: Emp 178 and Dep 190 both displayed!


Download ppt "Special Joins Week 4. Objective –Write SELECT statements to display left, right and full outer joins."

Similar presentations


Ads by Google