chapter 4 joining multiple tables. chapter objectives create a cartesian join create an equality...

Download Chapter 4 Joining Multiple Tables. Chapter Objectives Create a Cartesian join Create an equality join using the WHERE clause Create an equality join using

Post on 31-Mar-2015

214 views

Category:

Documents

0 download

Embed Size (px)

TRANSCRIPT

  • Slide 1

Chapter 4 Joining Multiple Tables Slide 2 Chapter Objectives Create a Cartesian join Create an equality join using the WHERE clause Create an equality join using the JOIN keyword Create a non-equality join using the WHERE clause Create a non-equality join using the JOINON approach Create a Cartesian join Create an equality join using the WHERE clause Create an equality join using the JOIN keyword Create a non-equality join using the WHERE clause Create a non-equality join using the JOINON approach Slide 3 Chapter Objectives Create a self-join Distinguish an inner join from an outer join Create an outer join using the WHERE clause Create an outer join using the OUTER keyword Use set operators to combine the results of multiple queries Join three or more tables Create a self-join Distinguish an inner join from an outer join Create an outer join using the WHERE clause Create an outer join using the OUTER keyword Use set operators to combine the results of multiple queries Join three or more tables Slide 4 Purpose of Joins Joins are used to link tables and reconstruct data in a relational database Joins can be created through: Conditions in a WHERE clause Use of JOIN keywords in FROM clause Joins are used to link tables and reconstruct data in a relational database Joins can be created through: Conditions in a WHERE clause Use of JOIN keywords in FROM clause Slide 5 Cartesian Join Created by omitting joining condition in the WHERE clause or through CROSS JOIN keywords in the FROM clause Results in every possible row combination (m * n) Created by omitting joining condition in the WHERE clause or through CROSS JOIN keywords in the FROM clause Results in every possible row combination (m * n) Slide 6 Cartesian Join Example: Omitted Condition Slide 7 Cartesian Join Example: CROSS JOIN Keywords Slide 8 Equality Join Links rows through equivalent data that exists in both tables Created by: Creating equivalency condition in the WHERE clause Using NATURAL JOIN, JOINUSING, or JOINON keywords in the FROM clause Links rows through equivalent data that exists in both tables Created by: Creating equivalency condition in the WHERE clause Using NATURAL JOIN, JOINUSING, or JOINON keywords in the FROM clause Slide 9 JOIN Keyword Overview Use NATURAL JOIN when tables have one column in common Use JOINUSING when tables have more than one column in common Use JOINON when a condition is needed to specify a relationship other than equivalency Using JOIN keyword frees the WHERE clause for exclusive use in restricting rows Use NATURAL JOIN when tables have one column in common Use JOINUSING when tables have more than one column in common Use JOINON when a condition is needed to specify a relationship other than equivalency Using JOIN keyword frees the WHERE clause for exclusive use in restricting rows Slide 10 Equality Join: WHERE Clause Example Slide 11 Equality Join: NATURAL JOIN Syntax: tablename NATURAL JOIN tablename Slide 12 Equality Join: JOINUSING Syntax: tablename JOIN tablename USING (columnname) Slide 13 Equality Join: JOINON Syntax: tablename JOIN tablename ON condition Slide 14 Non-Equality Joins In WHERE clause, use any comparison operator other than equal sign In FROM clause, use JOINON keywords with non-equivalent condition In WHERE clause, use any comparison operator other than equal sign In FROM clause, use JOINON keywords with non-equivalent condition Slide 15 Non-Equality Join: WHERE Clause Example Slide 16 Non-Equality Join: JOINON Example Slide 17 Self-Joins Used to link a table to itself Requires use of column qualifier Used to link a table to itself Requires use of column qualifier Slide 18 Self-Join: WHERE Clause Example Slide 19 Self-Join: JOINON Example Slide 20 Outer Joins Use to include rows that do not have a match in the other table In WHERE clause, include outer join operator (+) next to table with missing rows to add NULL rows In FROM clause, use FULL, LEFT, or RIGHT with OUTER JOIN keywords Use to include rows that do not have a match in the other table In WHERE clause, include outer join operator (+) next to table with missing rows to add NULL rows In FROM clause, use FULL, LEFT, or RIGHT with OUTER JOIN keywords Slide 21 Outer Join: WHERE Clause Example Slide 22 Outer Join: OUTER JOIN Keyword Example Slide 23 Set Operators Used to combine the results of two or more SELECT statements Slide 24 Set Operator Example Slide 25 Joining Three or More Tables Same procedure as joining two tables Will always results in one less join than the number of tables being joined Same procedure as joining two tables Will always results in one less join than the number of tables being joined Slide 26 Joining Three or More Tables: Example

Recommended

View more >