Understanding what a NATURAL JOIN is and how to use it

A NATURAL JOIN will associate columns of the same name in the joined tables with each other. It's similar to an INNER JOIN or a LEFT OUTER JOIN

To NATURAL JOIN two tables, use the following syntax: 

SELECT column(s)
FROM table1
NATURAL JOIN table2;

The previous syntax shows you how to join two tables together with NATURAL JOIN. You explicitly set the columns to be joined. 

The following example will help you to understand how to use NATURAL JOIN

SELECT c.playerid, c.schoolid, c.yearid, s.schoolid, city, state, country 
FROM lahmansbaseballdb.collegeplaying c
NATURAL JOIN lahmansbaseballdb.schools s;

You will receive the results from the previous query, as shown in the following screenshot:

These results will be from NATURAL JOIN finding the common column names in schools and collegeplaying, which in this case will be schoolid. It returns the results where the rows in each table match on schoolid.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.222.196.175