Beruflich Dokumente
Kultur Dokumente
6-1
Cross Joins and Natural Joins
DPS6L1 Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 3
Cross Joins and Natural Joins
Purpose
EMPLOYEES DEPARTMENTS
EMPLOYEE_ID LAST_NAME DEPT_ID DEPARTMENT_ID DEPT_NAME LOCATION_ID
100 King 90 10 Administration 1700
101 Kochhar 90 20 Marketing 1800
… …
202 Fay 20 110 Accounting 1700
205 Higgins 110 190 Contracting 1700
206 Gietz 110
DPS6L1 Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 4
Cross Joins and Natural Joins
Purpose
• But you know from data modeling Obtaining Data from Multiple Tables
that separating data into EMPLOYEE_ID DEPT_ID DEPT_NAME
individual tables and being able 200 10 Administration
201 20 Marketing
to associate the tables with one 202 20 Marketing
another is the heart of relational …
database design. 102
205
90
110
Executive
Accounting
206 110 Accounting
EMPLOYEES DEPARTMENTS
EMPLOYEE_ID LAST_NAME DEPT_ID DEPARTMENT_ID DEPT_NAME LOCATION_ID
100 King 90 10 Administration 1700
101 Kochhar 90 20 Marketing 1800
… …
202 Fay 20 110 Accounting 1700
205 Higgins 110 190 Contracting 1700
206 Gietz 110
DPS6L1 Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 5
Cross Joins and Natural Joins
Purpose
EMPLOYEES DEPARTMENTS
EMPLOYEE_ID LAST_NAME DEPT_ID DEPARTMENT_ID DEPT_NAME LOCATION_ID
100 King 90 10 Administration 1700
101 Kochhar 90 20 Marketing 1800
… …
202 Fay 20 110 Accounting 1700
205 Higgins 110 190 Contracting 1700
206 Gietz 110
DPS6L1 Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 6
Cross Joins and Natural Joins
Join Commands
DPS6L1 Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 7
Cross Joins and Natural Joins
ANSI
DPS6L1 Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 8
Cross Joins and Natural Joins
SQL
DPS6L1 Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 9
Cross Joins and Natural Joins
SQL
DPS6L1 Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 10
Cross Joins and Natural Joins
NATURAL JOIN
DPS6L1 Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 11
Cross Joins and Natural Joins
NATURAL JOIN
DPS6L1 Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 12
Cross Joins and Natural Joins
NATURAL JOIN
• This join will return columns from the employees table and
their related job_title from the jobs table based on the
common column job_id.
DPS6L1 Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 13
Cross Joins and Natural Joins
NATURAL JOIN
DPS6L1 Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 14
Cross Joins and Natural Joins
NATURAL JOIN
Contracting Seattle
• Notice that the natural join
column does not have to appear Marketing Toronto
DPS6L1 Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 15
Cross Joins and Natural Joins
CROSS JOIN
• The ANSI/ISO SQL: 1999 SQL CROSS JOIN joins each row in
one table to every row in the other table.
• The result set represents all possible row combinations from
the two tables.
• This could potentially be very large!
• If you CROSS JOIN a table with 20 rows with a table with 100
rows, the query will return 2000 rows.
DPS6L1 Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 16
Cross Joins and Natural Joins
Cross Join Example
DPS6L1 Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 17
Cross Joins and Natural Joins
Terminology
DPS6L1 Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 18
Cross Joins and Natural Joins
Summary
DPS6L1 Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 19
Cross Joins and Natural Joins