sql level 2 - powerpoint joins
TRANSCRIPT
-
8/11/2019 SQL level 2 - Powerpoint Joins
1/43
-
8/11/2019 SQL level 2 - Powerpoint Joins
2/43
Overview Natural Joins
1998 - 2013Bergin 2
-
8/11/2019 SQL level 2 - Powerpoint Joins
3/43
Joins are a technique for accessinginformation across tables.
Conceptually, a jo n takes the columns fromtwo tables and creates a new virtual table
with all of the columns. This is in contrast to a un on, which takes the
rows from two tables and forms a new tablewith all of the rows.
1998 - 2013Bergin 3
-
8/11/2019 SQL level 2 - Powerpoint Joins
4/43
1998 - 2013Bergin 4
-
8/11/2019 SQL level 2 - Powerpoint Joins
5/43
1998 - 2013Bergin 5
-
8/11/2019 SQL level 2 - Powerpoint Joins
6/43
SELECT column_list FROM table_list
SELECT
sid, name, majr,mcode, mname, dcode,dcode, dname
FROM
students, majors, divisions
1998 - 2013Bergin 6
-
8/11/2019 SQL level 2 - Powerpoint Joins
7/43
How do we get the right columns to line up? That is, how do we insure that the rows in the
students table match up with the right rowsin the majors table, match up with the rightrows in the division table?
1998 - 2013Bergin 7
-
8/11/2019 SQL level 2 - Powerpoint Joins
8/43
Via the WHERE Clause we can specify whichrows are to be included/maintained in theresult table.
WHEREstudents.majr = majors.mcode
and majors.dcode = divisions.dcode
How does this work?
1998 - 2013Bergin 8
-
8/11/2019 SQL level 2 - Powerpoint Joins
9/43
Conceptually, the FROM clause creates theCartesian product, or the cross product, ofthe two (or more) named tables.
1998 - 2013Bergin 9
-
8/11/2019 SQL level 2 - Powerpoint Joins
10/43 1998 - 2013Bergin 10
-
8/11/2019 SQL level 2 - Powerpoint Joins
11/43 1998 - 2013Bergin 11
-
8/11/2019 SQL level 2 - Powerpoint Joins
12/43 1998 - 2013Bergin 12
-
8/11/2019 SQL level 2 - Powerpoint Joins
13/43 1998 - 2013Bergin 13
-
8/11/2019 SQL level 2 - Powerpoint Joins
14/43
-
8/11/2019 SQL level 2 - Powerpoint Joins
15/43
The WHERE Clause then selects which rowsare to be maintained in the result table.
1998 - 2013Bergin 15
-
8/11/2019 SQL level 2 - Powerpoint Joins
16/43
1998 - 2013Bergin 16
-
8/11/2019 SQL level 2 - Powerpoint Joins
17/43
As the diagram / model suggests, joiningtables does not effect base tables.
Joining tables does not create base tables.
Joining tables creates working tables orvirtual tables that exist only for the durationof the inquiry.
1998 - 2013Bergin 17
-
8/11/2019 SQL level 2 - Powerpoint Joins
18/43
Another name for the cross product orCartesian product of two tables.
1998 - 2013Bergin 18
-
8/11/2019 SQL level 2 - Powerpoint Joins
19/43
Is a join based on equality, uses the equalityoperator (=).
1998 - 2013Bergin 19
-
8/11/2019 SQL level 2 - Powerpoint Joins
20/43
A form of the equi join, wherein theduplicated column is not displayed in theresult table.
1998 - 2013Bergin 20
-
8/11/2019 SQL level 2 - Powerpoint Joins
21/43
Is a join based on any comparison operator,other than the equality operator.
1998 - 2013Bergin 21
-
8/11/2019 SQL level 2 - Powerpoint Joins
22/43
Any kind of join based on any of thecomparison operators.
1998 - 2013Bergin 22
-
8/11/2019 SQL level 2 - Powerpoint Joins
23/43
These examples have all been inner joins. Aninner join is bound by a search expression,and disregards any rows where the searchcondition is not met.
1998 - 2013Bergin 23
-
8/11/2019 SQL level 2 - Powerpoint Joins
24/43
SELECT column_list FROM table_1CROSS JOIN table_2
1998 - 2013Bergin 24
-
8/11/2019 SQL level 2 - Powerpoint Joins
25/43
1998 - 2013Bergin 25
-
8/11/2019 SQL level 2 - Powerpoint Joins
26/43
1998 - 2013Bergin 26
-
8/11/2019 SQL level 2 - Powerpoint Joins
27/43
-
8/11/2019 SQL level 2 - Powerpoint Joins
28/43
1998 - 2013Bergin 28
-
8/11/2019 SQL level 2 - Powerpoint Joins
29/43
An outer join insures that rows from eitherone, or both tables are presented in the finalresult table.
1998 - 2013Bergin 29
-
8/11/2019 SQL level 2 - Powerpoint Joins
30/43
Specifies that each row in the first table (aslisted in the from clause) will be included inthe final result table.
1998 - 2013Bergin 30
-
8/11/2019 SQL level 2 - Powerpoint Joins
31/43
SELECT column_list FROM table_1 AS t1, table_2 AS t2
WHERE t1.column = t2.column
1998 - 2013Bergin 31
-
8/11/2019 SQL level 2 - Powerpoint Joins
32/43
SELECT column_list FROM table_1 AS t1, table_2 AS t2
WHERE t1.column = t2.column(+)
Note the plus sign goes with the table forwhich null values should be generated
1998 - 2013Bergin 32
-
8/11/2019 SQL level 2 - Powerpoint Joins
33/43
SELECT column_list FROM table_1LEFT OUTER JOIN table_2
1998 - 2013Bergin 33
-
8/11/2019 SQL level 2 - Powerpoint Joins
34/43
1998 - 2013Bergin 34
-
8/11/2019 SQL level 2 - Powerpoint Joins
35/43
Specifies that each row in the second table(as listed in the from clause) will be includedin the final result table.
1998 - 2013Bergin 35
-
8/11/2019 SQL level 2 - Powerpoint Joins
36/43
SELECT column_list FROM table_1 AS t1, table_2 AS t2
WHERE t1.column(+) = t2.column
1998 - 2013Bergin 36
-
8/11/2019 SQL level 2 - Powerpoint Joins
37/43
-
8/11/2019 SQL level 2 - Powerpoint Joins
38/43
1998 - 2013Bergin 38
-
8/11/2019 SQL level 2 - Powerpoint Joins
39/43
Specifies that each row in each table (asmentioned in the from clause) will beincluded in the final result table.
1998 - 2013Bergin 39
-
8/11/2019 SQL level 2 - Powerpoint Joins
40/43
SELECT column_list FROM table_1 AS t1, table_2 AS t2
WHERE t1.column(+) = t2.column(+)
Unfortunately this doesnt work!
1998 - 2013Bergin 40
-
8/11/2019 SQL level 2 - Powerpoint Joins
41/43
SELECT column_list FROM table_1FULL OUTER JOIN table_2
1998 - 2013Bergin 41
-
8/11/2019 SQL level 2 - Powerpoint Joins
42/43
-
8/11/2019 SQL level 2 - Powerpoint Joins
43/43