Difference between cross join and natural join in SQL.
Difference between cross join and natural join in SQL:
CROSS JOIN |
NATURAL JOIN |
It will represent
all the possible combination of rows from the two tables. It is also called
as cartesian product. It does not require the common column between the
tables. |
It combines
the tables based on the matching column name. Equality may be assumed
implicitly between the column of the tables. It eliminates duplicate columns
from the results. Matching column name should be same name and data type. It will
return all the rows from both tables where the matching column’s value are equal.
If the column with the same name but different data types may cause an issue. |
In this,
every row of one table is joined with every row of another table. |
In this, it
is like the join statement which compare the common column of both the tables
with each other. |
SYNTAX:
select * from table1 CROSS JOIN table2; |
SYNTAX:
select * from table1 NATURAL JOIN table2; |
It is more
used when the tables have unrelated data. |
It is more
used when the tables have related data. |
If table 1 has 4 rows and table 2 has 5 rows, it will provide result of table to 20 rows. The total number of rows returned is the product of the number of rows in the first table and the number of rows in the second table. |
If table 1
has 4 rows and table 2 has 4 rows, it will provide result of table of having
common column values match. |
Comments
Post a Comment