Union set operation in relational algebra, purpose of set union operation, example of set union relational algebra operation, relational algebra in dbms
Set Union Operation
Operation

UNION


Type of operation

Binary


Syntax

R_{1}
U R_{2}
Example: DEPOSITOR U BORROWER
(Expression_{1})
U (Expression_{2})
Example: Π _{regno}
(student) U Π _{regno} (sub_regd)


Rules to be satisfied

To
perform union operation, the following conditions must hold;
1. Both
the relations R_{1} and R_{2} (or the result of expression 1
and expression 2) must have the same number of attributes. That is, Arity should be same.
2. The
domain of i^{th} attribute of R_{1} and i^{th}
attribute of R_{2} must be same for all i.


Function

UNION
operation joins two relations vertically. That is, if we perform union
between relations R_{1} and R_{2}, then the records of R_{1}
and R_{2} become part of new relation. And, if any duplicate records
formed during this process, they will be eliminated.


Purpose

To
perform set operation. For example, assume that you have two relations as
depositor and borrower. If we would like to find the customers who are both
deposited and borrowed from the bank, we can perform union between these two
tables.


Example 1

RA: (Π _{max_age} (age_group)) U (Π _{age} (customer))
SQL: (SELECT
max_age FROM age_group) UNION (SELECT age FROM customer);
Result: Joins the tuples
of results of two expressions into one relation as follows;
See the result heading. It is max_age,
the attribute of left hand side expression.


Example 2

RA: (Π _{regno} (student)) U (Π _{regno} (sub_regd))
SQL: (SELECT
regno FROM student) UNION (SELECT regno FROM sub_regd);
Result: Joins the tuples
of two relations student and sub_regd into one relation as follows;
You can observe from the result, that the duplicate values are eliminated.
