Natural join in Relational algebra and SQL, natural join as in relational model, natural join examples with equivalent sql queries, difference between natural join and equijion
Natural join in Relational Algebra
Operation
|
NATURAL
JOIN
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Type of operation
|
Binary
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Syntax
|
R1 ⋈ R2
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Equivalent expression
|
R1 ⋈ R2 = σ<join condition>(R1 X R2)
Here, the <join
condition> is the Equijoin condition that checks for same/similar
attributes of R1 and R2.
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Function
|
Same as EQUIJOIN
except that the join attributes of R2 are not included in the
resulting relation; if the join attributes have the same names, they do not
have to be specified at all.
If R1(A, B, C) is
joined with R2(A, D, E), then it produces a new temporary relation R(A, B, C,
D, E). The result consists of all records that satisfy the join condition.
Also, observe that R does not include A twice.
Natural
join is just like equi-join. Only difference is that the common attribute is
not included in the result twice in natural join unlike equi-join.
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Example 1
|
RA: (student
⋈ sub_regd)
SQL: SELECT
regno, name, age, phone, subject FROM student, sub_regd WHERE student.regno =
sub_regd.regno;
Result: Joins the two
relations student and sub_regd on regno attributes. If
the values of the join attributes are same, only those records are combined
as shown below.
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Example 2
|
RA: (Π regno, name, age, phone (student))
⋈ (Π regno, subject (sub_regd)
SQL: SELECT
* FROM student natural join sub_regd;
Result: Produces a new
temporary relation with regno, name, phone, sregno and subject attributes of
all students. The records that satisfy the join condition regno = sregno are
included in the final result.
Example 1 and 2, both produces same
result.
Note:
If you have common attributes with different names, then you can use rename
operation before perform natural join.
|
*************
Go to Relational Algebra Operations page