CSIT 4th DBSM Note

1. Natural Join : 
Natural Join joins two tables based on same attribute name and datatypes. The resulting table will contain all the attributes of both the table but keep only one copy of each common column. 

Example: 
Consider the two tables given below: 

Student Table 

CSIT 4th DBSM Note: Difference between Natural join and Inner Join in SQL

Marks Table 


 

CSIT 4th DBSM Note: Difference between Natural join and Inner Join in SQL

Consider the given query 

SELECT * 
FROM Student NATURAL JOIN Marks;

Output:

CSIT 4th DBSM Note: Difference between Natural join and Inner Join in SQL

Also Read: SQL Joins – All You Need To Know About SQL Joins

2. Inner Join : 
Inner Join joins two table on the basis of the column which is explicitly specified in the ON clause. The resulting table will contain all the attributes from both the tables including common column also. 

Example: 
Consider the above two tables and the query is given below: 

SELECT * 
FROM student S INNER JOIN Marks M ON S.Roll_No = M.Roll_No; 

Output : 

CSIT 4th DBSM Note: Difference between Natural join and Inner Join in SQL

Difference between Natural JOIN and INNER JOIN in SQL : 

SR.NO.NATURAL JOININNER JOIN
1.Natural Join joins two tables based on same attribute name and datatypes.Inner Join joins two table on the basis of the column which is explicitly specified in the ON clause.
2.In Natural Join, The resulting table will contain all the attributes of both the tables but keep only one copy of each common columnIn Inner Join, The resulting table will contain all the attribute of both the tables including duplicate columns also
3.In Natural Join, If there is no condition specifies then it returns the rows based on the common columnIn Inner Join, only those records will return which exists in both the tables
4.SYNTAX: 
SELECT * 
FROM table1 NATURAL JOIN table2; 
 
SYNTAX: 
SELECT * 
FROM table1 INNER JOIN table2 ON table1.Column_Name = table2.Column_Name; 

Also Read:


0 Comments

Leave a Reply