Relational Algebra - UNION (∪) Operation
1. Definition
The UNION operation in relational algebra combines tuples from two relations and returns a new relation containing all unique tuples that appear in either or both of the original relations. Duplicate tuples are eliminated in the result.
2. Union Compatibility
For two relations to be union compatible, the following conditions must be satisfied:
- Same Degree (Arity):
- The number of attributes (columns) in both relations must be the same.
- Example: If Relation P has 3 attributes, Q must also have 3 attributes.
- Matching Attribute Domains:
- Corresponding attributes in both relations must have the same domain (data type).
- Example: If
P1
in Relation P is of type Integer
, then Q1
in Relation Q must also be of type Integer
.
Mathematically:
- Let
P = {P1, P2, ..., Pn}
and Q = {Q1, Q2, ..., Qn}
.
- The domains of attributes must satisfy: Dom(Pi) = Dom(Qi) for all
i = 1, 2, ..., n
.
3. Result of UNION
The result of a union operation, say R = P ∪ Q, will:
- Contain all tuples that are in P, Q, or both.
- Eliminate duplicate tuples.
- Have the same degree as P and Q (since the relations are union-compatible).