A NATURAL JOIN is a JOIN operation that creates an implicit join clause for you based on the common columns in the two tables being joined. A NATURAL JOIN can be an INNER join, a LEFT OUTER join, or a RIGHT OUTER join. The default is INNER join. Source
So a natural join can be a shorthand way of implementing inner join if both tables have a common column.
Consider following table:
SELECT * FROM t1;
/*
ID PLANET
---------- --------
1 jupiter
2 earth
*/
We join the table to itself:
SELECT first.id, first.planet FROM t1 first INNER JOIN t1 second ON first.id=second.id;
/*
ID PLANET
---------- --------
1 jupiter
2 earth
*/
Try to do the same with natural join notation:
SELECT id, planet FROM t1 NATURAL JOIN t1;
/*
ID PLANET
---------- --------
1 jupiter
1 jupiter
2 earth
2 earth
*/
Given that natural join here is implemented using inner join why the multiple rows?
Update:
Running same join with table aliases has different output:
SELECT id, planet FROM t1 first NATURAL JOIN t1 second;
/*
ID PLANET
---------- --------
1 jupiter
2 earth
*/
PLANET
as a common column, is that causing the duplicates?SELECT first.id, first.planet FROM t1 first NATURAL JOIN t1 second
?