Definition
Natural Join (Relational Algebra)
The natural join combines two relations via common attributes (same names and domains) by combining only tuples with the same values for common attributes.
Given two relations and , the natural join can be expressed using projection, selection and the Cartesian Product:
Example
Given two relations and :
Students Relation:
StudentID | Name | Major |
---|---|---|
S101 | Alice | Physics |
S102 | Bob | CS |
S103 | Charlie | Biology |
Enrolments Relation:
StudentID | CourseID | Grade |
---|---|---|
S101 | C22 | A |
S102 | C15 | B |
S102 | C22 | A |
S104 | C15 | C |
There’s only one common attribute, namely StudentID
. Therefore, the join condition is:
Thus, the resulting relation is:
StudentID | Name | Major | CourseID | Grade |
---|---|---|---|---|
S101 | Alice | Physics | C22 | A |
S102 | Bob | CS | C15 | B |
S102 | Bob | CS | C22 | A |