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,
ID | NAME |
---|---|
1 | abhi |
2 | adam |
3 | alex |
4 | anu |
The class_info table,
ID | Address |
---|---|
1 | DELHI |
2 | MUMBAI |
3 | CHENNAI |
Natural join query will be,
SELECT * from class NATURAL JOIN class_info;
The result table will look like,
ID | NAME | Address |
---|---|---|
1 | abhi | DELHI |
2 | adam | MUMBAI |
3 | alex | CHENNAI |
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