More Relational Algebra
Set Operations on Relations CARTESIAN PRODUCT UNION INTERSECTION DIFFERENCE
JOIN More flavors SEMIJOIN – OUTERJOIN “If A and B are tables, then the left-semijoin A|XB, is found by taking the natural join of A and B and then projecting the result onto the attributes of A. The result will be just those tuples of A that participate in the join.” Ricardo, p. 192 Equivalent Examples: Student LEFT-SEMIJOIN Enroll Student |X Enroll OUTERJOIN “This operation is an extension of a THETA JOIN, an EQUIJOIN or a NATURAL JOIN operation. When forming any of these joins, any tuple from one of the original tables for which there is no match in the second table does not enter the result.” Ricardo p. 193 LEFT OUTER EQUIJOIN & RIGHT OUTER EQUIJOIN Are variations of the outer equijoin Ricardo p. 194, 1953
Terminology For two relations to be union compatible each relation must have the same number of attributes, and the attributes in corresponding columns must come from the same domain.
Relation Operations Difference The difference of two relations is a third relation containing tuples that occur in the first relation but not in the second. The relations must be union compatible A-B is not the same as B-A
Relation Operations Union The union of two relations is formed by adding the tuples from one relation to those of a second relation to produce a third relation. The order in which the tuples appear in the third relation is not important. Duplicate tuples must be eliminated The relations must be union compatible
Relation Operations Intersection The intersection of two relations is a third relation containing the tuples that appear in both the first and the second relation. The relations must be union compatible
Relation Definitions
Attribute Domains
Domain Definitions
JUNIOR relation (a) HONOR-STUDENT relation (b)
Union of JUNIOR and HONOR-STUDENT relations
Summary of Relational Algebra Operations