Sunday, May 3, 2015

SQL Natural JOIN

Natural Join is a type of Inner join which is based on column having same name and same datatype present in both the tables to be joined.
Natural Join Syntax is,
SELECT *
from table-name1 
NATURAL JOIN 
table-name2;

Example of Natural JOIN

The class table,
IDNAME
1abhi
2adam
3alex
4anu
The class_info table,
IDAddress
1DELHI
2MUMBAI
3CHENNAI
Natural join query will be,
SELECT * from class NATURAL JOIN class_info; 
The result table will look like,
IDNAMEAddress
1abhiDELHI
2adamMUMBAI
3alexCHENNAI
In the above example, both the tables being joined have ID column(same name and same datatype), hence the records for which value of ID matches in both the tables will be the result of Natural Join of these two tables.

No comments:

Post a Comment