Natural join if no common attributes
Asked Answered
T

3

23

What will natural join return in relational algebra if tables don't have attributes with same names? Will it be null or the same as cross join (cross product) (Cartesian product)?

Tonsure answered 27/1, 2013 at 14:48 Comment(0)
P
31

If there are no attributes in common between two relations and you perform a natural join, it will return the cartesian product of the two relations.

Propulsion answered 10/2, 2013 at 14:50 Comment(4)
A natural join is a join where all columns in both tables are compared and columns with the same name in either table are joined. The result is a table with a single column for each of these paired tables. If there are no columns in common, there is nothing to be joined, so everything gets joined with everything - i.e. a cartesian product.Propulsion
It joins the info on the columns if they have the same name. It then joins all other columns based on this. So if table A has column 1 and 2 and table B has column 2, 3 and 4, a cartesian product will create a single table with column 1, 2, 3, 4. It will determine how to match this based on the joining of the two column "2"s. If there are no common columns, the result set you are left with is everything in table a and everything in table b - hence every tuple in table b gets joined with the first tuple in table a, then every tuple gets joined with the second tuple in table a and so on.Propulsion
Here's an example of the natural join: en.wikipedia.org/wiki/… And then another example, this time of a cartesian product: en.wikipedia.org/wiki/Cartesian_product#ExamplesPropulsion
A follow-up question: A natural join is classified as an "inner" join. My colloquial definition of an inner join is that only values where a match is produced in the join condition are kept. In the case of no matching columns, nothing is matched. Wouldn't that operation violate the "inner" criteria?Archive
D
8

The cartesian product of the two tables will be returned. This is because, when we perform any JOIN operation on two tables, a cartesian product of those tables is formed. Then, based on any select condition in the WHERE clause, the resultant rows are returned. But here, as there are no common columns, the process stops after finding the cartesian product.

Dariodariole answered 11/7, 2014 at 14:23 Comment(1)
"Then, based on any select condition in the WHERE clause, the resultant rows are returned." False. Natural join does not return a restriction/selection of a Cartesian product when there are common columns. It returns what can roughly be described as a certain projection of a restriction/selection of a Cartesian product--although describing it correctly depends on the algebra's relations & operators.Overspread
I
-1

It will return the cartesian product of the tables. If there are any common attributes, then the natural join removes the duplicate attributes.

Iodine answered 7/3, 2014 at 13:16 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.