Relational algebra Types of operations Set theoretic operations Union operator Intersection operator Difference operator Cartesian product operator Selection operator Project operator Joins Division operation Some examples
Union, Intersection and Difference Operands need to be union compatible for the result to be a valid relation Definition : Two relations R1 and R2 are union compatible iff: They have the same number of attributes. Corresponding fields have the same type.
The result R1 R2 is a relation that includes all tuples that are either in R1 or in R2 or in both without duplicate tuples. The resulting relation might have the same attribute names as the first or the second relation.
The result R1 R2 is a relation that includes only those tuples : That are in R1 and also appear in R2. The resulting relation might have the same attribute names as the first or the second relation
Definition: Result schema has one field per field of P and Q, with field names `inherited’ if possible. The result, denoted by PXQ, is a relation that includes all the possible combinations of tuples from P and Q Used in conjunction with other operations
Selects rows that satisfy selection condition. No duplicates in result! Schema of result identical to schema of (only) input relation. Result relation can be the input for another relational algebra operation! (Operator composition.)
Deletes attributes that are not in projection list. Schema of result contains exactly the fields in the projection list, with the same names that they had in the (only) input relation. Result = (attribute list) (relation name) Resulting relation has only the attributes in the list, in same order as they appear in the list the degree(result) = number of attributes in the attribute list no duplicates in the result attribute list are drawn from the specified relation ;
stands for the usual comparison operators ‘ ‘, ‘>=‘, etc The result is a concatenated set but only for those tuples where the condition is true. It does not require union compatibility of R1 and R2 Result = R1 ( join condition) R2 Fewer tuples than cross-product, might be able to compute more efficiently
Definition: The division of two relations R1(A 1,A 2,...,A n ) with cardinality i and R2(B 1,B 2,...,B m ) with cardinality j is a relation R3 with degree k=n-m, cardinality i*j and attributes (A 1,A 2,...,A n,B 1,B 2,...,B m ) that satisfy the division condition The principle algebraic counterpart of queries that involve the universal quantifier Relational languages do not express relational division