Binary Relational Operations
Binary Relational Operations
– A special operation, called JOIN combines this sequence into a single operation
– This operation is very important for any relational database with more than a single
relation, because it allows us combine related tuples from various relations
– The general form of a join operation on two relations R(A1, A2, . . ., An) and S(B1,
B2, . . ., Bm) is:
R<join condition>S
– Where R and S can be any relations that result from general relational algebra
expressions.
– Example: Suppose that we want to retrieve the name of the manager of each department.
– To get the manager’s name, we need to combine each DEPARTMENT tuple with the
EMPLOYEE tuple whose SSN value matches the MGRSSN value in the department tuple.
– Combines each department record with the employee who manages the department
R.Ai=S.Bj
– The resulting relation state has one tuple for each combination of tuples—r from R and s
from S, but only if they satisfy the join condition r[Ai]=s[Bj]
– Hence, if R has nR tuples, and S has nS tuples, then the join result will generally have less
than nR * nS tuples.
– Only related tuples (based on the join condition) will appear in the result
• Theta can be any general boolean expression on the attributes of R and S; for example:
• Most join conditions involve one or more equality conditions “AND”ed together; for example:
• The most common use of join involves join conditions with equality comparisons only
• Such a join, where the only comparison operator used is =, is called an EQUIJOIN.
– In the result of an EQUIJOIN we always have one or more pairs of attributes (whose
names need not be identical) that have identical values in every tuple.
Another variation of JOIN called NATURAL JOIN — denoted by * — was created to get rid of the second
(superfluous) attribute in an EQUIJOIN condition.
The standard definition of natural join requires that the two join attributes, or each pair of
corresponding join attributes, have the same name in both relations