sql – difference between natural join and inner join – Stack Overflow
One significant difference between INNER JOIN and NATURAL JOIN is the number of columns returned.
Consider:
TableA TableB
Column1 Column2 Column1 Column3
1 2 1 3
The INNER JOIN of TableA and TableB on Column1 will return
a.column1 a.column2 b.column1 b.column3
1 2 1 3
SELECT * FROM TableA INNER JOIN TableB USING (Column1)
SELECT * FROM TableA INNER JOIN TableB ON TableA.Column1 = TableB.Column1
The NATURAL JOIN of TableA and TableB on Column1 will return:
column1 column2 column3
1 2 3
SELECT * FROM TableA NATURAL JOIN TableB
The repeated column is avoided.
(AFAICT from the standard grammar, you can’t specify the joining columns in a natural join; the join is strictly name-based. See also Wikipedia.)
(There’s a cheat in the inner join output; the a.
and b.
parts would not be in the column names; you’d just have column1
, column2
, column1
, column3
as the headings.)