Académique Documents
Professionnel Documents
Culture Documents
RetrievingDatafrom
SeveralTables
The primary keys and foreign keys are used to join related
tables to one another.
What is a Join?
Types of Join
*PropertyofSTI
K0019
1 _________________________
___________________________
___________________________
___________________________
___________________________
___________________________
___________________________
___________________________
___________________________
Types of Joins
*PropertyofSTI
K0019
2__________________________
___________________________
___________________________
___________________________
___________________________
___________________________
___________________________
___________________________
___________________________
Types of Joins
Syntax:
Example:
*PropertyofSTI
K0019
3 _________________________
___________________________
___________________________
___________________________
___________________________
___________________________
___________________________
___________________________
___________________________
*PropertyofSTI
K0019
4__________________________
___________________________
___________________________
___________________________
___________________________
___________________________
___________________________
___________________________
___________________________
Types of Joins
Types of Joins
Natural Joins
Example:
SELECT product.*,
order_items.quantity
Syntax:
K0019
5 _________________________
___________________________
___________________________
___________________________
___________________________
___________________________
___________________________
___________________________
___________________________
Types of Joins
K0019
6__________________________
___________________________
___________________________
___________________________
___________________________
___________________________
___________________________
___________________________
___________________________
Types of Joins
Non-equijoins
*PropertyofSTI
Non-equijoins (cont.)
Example:
SELECT EMPLOYEE_TBL.EMP_ID,
SALARY_TBL.DATE_HIRE
Syntax:
FROM EMPLOYEE_TBL,
SALARY_TBL
[ TABLE3.COLUMN_NAME ]
*PropertyofSTI
K0019
7 _________________________
___________________________
___________________________
___________________________
___________________________
___________________________
___________________________
___________________________
___________________________
*PropertyofSTI
K0019
8__________________________
___________________________
___________________________
___________________________
___________________________
___________________________
___________________________
___________________________
___________________________
Types of Joins
Types of Joins
Outer Joins
It produces all rows that exist in one table, even if there are
corresponding rows do not exist in the joined table.
Syntax:
The left outer join preserves every row in the left-hand table.
Example:
*PropertyofSTI
K0019
9 _________________________
___________________________
___________________________
___________________________
___________________________
___________________________
___________________________
___________________________
___________________________
Types of Joins
*PropertyofSTI
K0019
10 ________________________
___________________________
___________________________
___________________________
___________________________
___________________________
___________________________
___________________________
___________________________
Types of Joins
Self Joins
Syntax:
Example:
FROM EMPLOYEE_TBL A,
EMPLOYEE_TBL B
*PropertyofSTI
K0019
11 ________________________
___________________________
___________________________
___________________________
___________________________
___________________________
___________________________
___________________________
___________________________
*PropertyofSTI
K0019
12 ________________________
___________________________
___________________________
___________________________
___________________________
___________________________
___________________________
___________________________
___________________________
Types of Joins
Cross Joins
Syntax:
SELECT *
FROM TABLE1 CROSS JOIN TABLE2
Example:
SELECT *
FROM ORDER CROSS JOIN PURCHASE
*PropertyofSTI
K0019
13 ________________________
___________________________
___________________________
___________________________
___________________________
___________________________
___________________________
___________________________
___________________________