Module2 Chapter3
Module2 Chapter3
Algebra and
Relational
Calculus
Relational algebra
Basic set of operations for the relational model
Relational algebra expression
Sequence of relational algebra operations
Relational calculus
Higher-level declarative language for specifying relational
queries
Example: For example, to select the tuples for all employees who
either work in department 4 and make over $25,000 per year, or
work in department 5 and make over $30,000, we can specify the
following SELECT operation:
Rename attributes in intermediate results which can rename either the relation
name or the attribute names, or both—as a unary operator.
The relation RESULT1 has the Ssn of all employees who work in department 5, whereas
RESULT2 has the Ssn of all employees who directly supervise an employee who works in
department 5. The UNION operation produces the tuples that are in either RESULT1 or RESULT2
or both
INTERSECTION
R∩S
Includes all tuples that are in both R and S
SET DIFFERENCE (or MINUS)
R–S
Includes all tuples that are in R but not in S
Ai is an attribute of R
Bj is an attribute of S
Ai and Bj have the same domain
θ (theta) is one of the comparison operators:
• {=, <, ≤, >, ≥, ≠}
A JOIN operation with such a general join condition is called a THETA JOIN.
The same query can be done in two steps by creating an intermediate table
DEPT as follows:
The attribute Dnum is called the join attribute for the NATURAL JOIN operation,
because it is the only attribute with the same name in both relations.
Copyright © 2011 Ramez Elmasri and Shamkant Navathe
Copyright © 2011 Ramez Elmasri and Shamkant Navathe
The EQUIJOIN and NATURAL JOIN
• If the attributes on which the natural join is specified already have the same
names in both relations, renaming is unnecessary.
• For example, to apply a natural join on the Dnumber attributes of
DEPARTMENT and DEPT_LOCATIONS, it is sufficient to write
Next, create a relation that includes a tuple whenever the employee whose Ssn is
Essn works on the project whose number is Pno in the intermediate relation
SSN_PNOS:
Finally, apply the DIVISION operation to the two relations, which gives the
desired employees’ Social Security numbers: