Collection Contents Index Key joins Joins using comparisons pdf/chap6.pdf

User's Guide
   PART 1. Working with Databases
     CHAPTER 6. Joins: Retrieving Data from Several Tables       

Natural joins


A natural join matches the rows from two tables by comparing the values from columns, one in each table, that have the same name. It restricts the results by comparing the values of columns in the two tables with the same column name. An error is reported if there is no common column name.

For example, you can join the employee and department tables using a natural join because they have only one column name in common.

SELECT emp_fname, emp_lname, dept_name
FROM employee NATURAL JOIN department
ORDER BY dept_name, emp_lname, emp_fname

emp_fname

emp_lname

dept_name

Janet

Bigelow

Finance

Kristen

Coe

Finance

James

Coleman

Finance

Jo Ann

Davidson

Finance

Denis

Higgins

Finance

Julie

Jordan

Finance

John

Letiecq

Finance

Jennifer

Litton

Finance

Mary Anne

Shea

Finance

Alex

Ahmed

Marketing

Irene

Barletta

Marketing

Barbara

Blaikie

Marketing

Column names such as description or address often cause a NATURAL JOIN to return different results than expected. Another means of specifying a join is by means of a condition, supplied within an ON phrase. Here, you have a wide number of options at your disposal.


Collection Contents Index Key joins Joins using comparisons pdf/chap6.pdf