Jointures
Jointures
Jointures
Multiple Tables
www.supinfo.com
Copyright © SUPINFO. All rights reserved
Displaying Data from Multiple Tables
Course objectives
By completing this course, you will be able to:
Course topics
Course’s plan:
Displaying Data from
Multiple Tables
Displaying Data from Multiple Tables
Preview
Joins: Presentation.
Types of joins.
Qualifying Ambiguous Column
Names.
Natural Joins.
The ON Clause.
Non-equijoins.
Outer Joins.
Cross Joins.
Displaying Data from Multiple Tables
Joins: Presentation
EMPLOYEES DEPARTMENTS
Displaying Data from Multiple Tables
Types of Joins
Joins that are compliant with the SQL:1999 standard
include the following:
Cross joins
Natural joins
USING clause
Full (or two-sided) outer joins
Arbitrary join conditions for outer joins
Displaying Data from Multiple Tables
Types of Joins
Joining Tables Using SQL:1999 Syntax:
Natural Joins
Creating Natural Joins:
The NATURAL JOIN clause is based on all columns in the
two tables that have the same name.
It selects rows from the two tables that have equal values
in all matched columns.
If the columns having the same names have different data
types, an error is returned.
Displaying Data from Multiple Tables
Natural Joins
Retrieving Records with Natural Joins:
Natural Joins
Creating Joins with the USING Clause:
If several columns have the same names but the data
types do not match, the NATURAL JOIN clause can be
modified with the USING clause to specify the columns
that should be used for an equijoin.
Use the USING clause to match only one column when
more than one column matches.
Do not use a table name or alias in the referenced
columns.
The NATURAL JOIN and USING clauses are mutually
exclusive.
Displaying Data from Multiple Tables
Natural Joins
Joining Column Names:
… …
Natural Joins
Retrieving Records with the USING Clause:
The ON Clause
Creating Joins with the ON Clause:
The join condition for the natural join is basically an
equijoin of all columns with the same name.
Use the ON clause to specify arbitrary conditions or
specify columns to join.
The join condition is separated from other search
conditions.
The ON clause makes code easy to understand.
Displaying Data from Multiple Tables
The ON Clause
Retrieving Records with the ON Clause:
The ON Clause
Self-Joins Using the ON Clause:
The ON Clause
Self-Joins Using the ON Clause:
The ON Clause
Applying Additional Conditions to a Join:
The ON Clause
Creating Three-Way Joins with the ON Clause:
Non-equijoins
EMPLOYEES JOB_GRADES
Non-equijoins
Retrieving Records with Non-Equijoins:
Outer Joins
DEPARTMENTS EMPLOYEES
Outer Joins
INNER Versus OUTER Joins:
In SQL:1999, the join of two tables returning only
matched rows is called an inner join.
A join between two tables that returns the results of the
inner join as well as the unmatched rows from the left (or
right) tables is called a left (or right) outer join.
A join between two tables that returns the results of an
inner join as well as the results of a left and right join is a
full outer join.
Displaying Data from Multiple Tables
Outer Joins
LEFT OUTER JOIN:
Outer Joins
RIGHT OUTER JOIN:
Outer Joins
FULL OUTER JOIN:
Cross Joins
Cartesian Products:
A Cartesian product is formed when:
A join condition is omitted
A join condition is invalid
All rows in the first table are joined to all rows in the
second table
To avoid a Cartesian product, always include a valid join
condition.
Displaying Data from Multiple Tables
Cross Joins
Generating a Cartesian Product:
Cartesian product:
20 x 8 = 160 rows
Displaying Data from Multiple Tables
Cross Joins
Creating Cross Joins:
The CROSS JOIN clause produces the cross product of
two tables.
This is also called a Cartesian product between the two
tables.
SELECT last_name, department_name
FROM employees
CROSS JOIN departments ;
Displaying Data from Multiple Tables
Part 1 Stop-and-think
Part 1 Summary
Types of Qualifying
Joins:
joins Ambiguous
Presentation
Column
Names
Natural
Joins The ON
Clause
Non-
equijoins
Outer Cross
Joins Joins
Displaying Data from Multiple Tables
For more
If you want to go into these subjects more deeply, …
Publications Courses
http://www.labo-oracle.com 1Z0-007
http://www.oracle.com
http://otn.oracle.com
Congratulations
You have successfully completed the
SUPINFO course n°4
Oracle Technologies
Displaying Data from Multiple Tables
Displaying Data from Multiple Tables
The end