Presentation is loading. Please wait.

Presentation is loading. Please wait.

IFS180 Intro. to Data Management Chapter 9 – Outer Joins.

Similar presentations


Presentation on theme: "IFS180 Intro. to Data Management Chapter 9 – Outer Joins."— Presentation transcript:

1 IFS180 Intro. to Data Management Chapter 9 – Outer Joins

2 Review of Inner Join Function Purpose of inner join is to create a result set of related or matching rows between tables Challenging when you don’t know the data set, hence you need some form of relationship diagram (ERD) Two tables are relatively straight forward From table name inner join table name on search criteria Embedded select statement valid any place a table name can be used

3 Review of Inner Join Embedded select statements good when: Result set is subset of columns filtered on a particular characteristic associated with column in the result set (example) Need to calculate / accumulate values from one table to be used with calculations on columns from another table (due to the normalized form rule of no accumulated values) No rule of thumb other than performance issues (however, you will find they are also common in where clause)

4 Review of Inner Join Three or more tables Table one and two form a logical table Logical table is joined to table 3 forming one logical table Logical table joins are repeated until number of left parenthesis equal number of right parenthesis (((( …. )))) Example

5 Difference in Set Theory Unlike Intersection set theory (commonality) difference in set theory seeks difference among sets (Again) to compare sets, all member in the sets must have the same number and type of attributes Difference between set one and set two are those members (of set one) that have different attributes from set two Difference between set two and set one are those members (of set two) that have different attributes from set one

6 Difference in Set Theory Identification BlackAllisterSeattleWA166 HallmarkJoeWoodinWA157 EhrlichZacharySeattleWA143 RojalesJoeTacomaWA166 PattersonRachelAuburnWA157 RiserBrianSeattleWA152 HindmanRickDuvallWA145 MankenDonBellevueWA157 RojalesJoeTacomaWA166 JonesFredSeattleWA158 First NameLast NameCityStAvg 5 10 7 15 17 1 3 8 15 20 Primary Key Tuesday League Primary Key Monday League

7 Difference Set Theory Intersection use to find equality between one or more data sets and inequality Members in Seattle Members Names not Joe Average > 160 Seattle and not Joe Seattle, not Joe, > 160

8 Difference Set theory difference implemented in SQL standard with the (Outer) JOIN operation Imperative to understand the relationships between the tables Purpose of the Outer Join is to return rows that match your criteria and to include unmatched rows from either one or both of the sets you want to link

9 Outer Join Generally, dealing with one-to-many table relationship. Parent / Child relationship Where Parent in one table may have zero or more “children” rows Where the zero or many “children” rows have one parent row When selecting rows with outer join, interested in all rows from one table and any matching rows from a second table Null will be used frequently

10 Left Outer Join Basic syntax: From table name LEFT OUTER JOIN table name ON Cartesian Product is created (logical combination of all rows in both tables) The search criteria of the ON statement is applied to select desired rows. Remember to fully qualify column names

11 Left Outer Join First table named is the “left” table Used when all rows in “left” / first table are required and any matching rows from the second table SQL default is an inner join, therefore you must declare left outer join Critical portion of the (any) join statement is the ON (or using) statement where the actual selection occurs

12 Join with Embedded Select Statements Working with more than two table Substitute a complete select statement for a table name Requires a correlation name assigned to the embedded select (for reference purposes) Embedded select may include all clauses except order by clause In essence, query within a query and you must return any column and linking values for joins

13 Embedding Joins within Joins Use with caution. Potential Performance issues exit Anywhere a table name can be specified, a join clause surrounded with parentheses may be used Just like embedded inner joins, a “logical” table is created on the two joined tables

14 Other Join Types Full Outer Join Both a left and right outer join Null values are established when no matching values exist on the left or right side Union Join Full outer join with matches omitted. Uses?

15 Outer join uses Finding missing values What products have never been ordered List entertainers who have never been booked Display students who have never withdrawn from a class List ingredients not used in any recipe

16 Outer Join Uses Finding partially matched information List all products and the dates for any order List all bowlers and games they bowled over 160.


Download ppt "IFS180 Intro. to Data Management Chapter 9 – Outer Joins."

Similar presentations


Ads by Google