0% found this document useful (0 votes)
50 views

Binary Relational Operations

The document discusses different types of binary relational operations in databases including JOIN, EQUIJOIN, and NATURAL JOIN. It explains that JOIN combines related tuples from two relations based on a join condition. EQUIJOIN uses only equality comparisons in the join condition. NATURAL JOIN removes duplicate attributes from the join condition when the attributes have the same name.

Uploaded by

09whitedevil90
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
50 views

Binary Relational Operations

The document discusses different types of binary relational operations in databases including JOIN, EQUIJOIN, and NATURAL JOIN. It explains that JOIN combines related tuples from two relations based on a join condition. EQUIJOIN uses only equality comparisons in the join condition. NATURAL JOIN removes duplicate attributes from the join condition when the attributes have the same name.

Uploaded by

09whitedevil90
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

lOMoARcPSD|39225634

Binary Relational Operations

Intro To Database Appl (Montgomery College)

Scan to open on Studocu

Studocu is not sponsored or endorsed by any college or university


Downloaded by White Devil (09whitedevil90@gmail.com)
lOMoARcPSD|39225634

Binary Relational Operations


Binary Relational Operations: JOIN
• JOIN Operation (denoted by

– The sequence of CARTESIAN PRODECT followed by SELECT is used quite commonly to


identify and select related tuples from two relations

– 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.

– We do this by using the join operation.

– DEPT_MGR  DEPARTMENT MGRSSN=SSN EMPLOYEE

– MGRSSN=SSN is the join condition

– Combines each department record with the employee who manages the department

– The join condition can also be specified as DEPARTMENT.MGRSSN= EMPLOYEE.SSN

Example of applying the JOIN operation

Some properties of JOIN


• Consider the following JOIN operation:

– R(A1, A2, . . ., An) S(B1, B2, . . ., Bm)

Downloaded by White Devil (09whitedevil90@gmail.com)


lOMoARcPSD|39225634

R.Ai=S.Bj

– Result is a relation Q with degree n + m attributes:

• Q(A1, A2, . . ., An, B1, B2, . . ., Bm), in that order.

– 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

• The general case of JOIN operation is called a Theta-join: R theta S

• The join condition is called theta

• Theta can be any general boolean expression on the attributes of R and S; for example:

– R.Ai<S.Bj AND (R.Ak=S.Bl OR R.Ap<S.Bq)

• Most join conditions involve one or more equality conditions “AND”ed together; for example:

– R.Ai=S.Bj AND R.Ak=S.Bl AND R.Ap=S.Bq

Binary Relational Operations: EQUIJOIN


• EQUIJOIN Operation

• 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.

– The JOIN seen in the previous example was an EQUIJOIN.

Binary Relational Operations: NATURAL JOIN Operation


NATURAL JOIN Operation

Another variation of JOIN called NATURAL JOIN — denoted by * — was created to get rid of the second
(superfluous) attribute in an EQUIJOIN condition.

Because one of each pair of attributes with identical values is superfluous

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

If this is not the case, a renaming operation is applied first.

Downloaded by White Devil (09whitedevil90@gmail.com)


lOMoARcPSD|39225634

Example: To apply a natural join on the DNUMBER attributes of


DEPARTMENT and DEPT_LOCATIONS, it is sufficient to write:
DEPT_LOCS DEPARTMENT * DEPT_LOCATIONS
Only attribute with the same name is DNUMBER
An implicit join condition is created based on this attribute:
DEPARTMENT.DNUMBER=DEPT_LOCATIONS.D NUMBER

Downloaded by White Devil (09whitedevil90@gmail.com)

You might also like