Relational Algebra – Union (∪) Operation in DBMS

Relational Algebra Operations – Union (∪)

The Union Operation in Relational Algebra combines the tuples (rows) of two relations (tables) and removes any duplicate tuples. It is similar to the UNION operation in SQL.


🔹 Definition

The Union operation is a binary operation (it works on two relations). It produces a new relation containing all tuples that appear in either or both of the input relations.

Notation:

R ∪ S

Here, R and S are two relations with the same structure (same number of attributes and same attribute domains).


🔹 Union Compatibility Rules

Two relations can be combined using Union only if they are Union Compatible.

Conditions:

  • Both relations must have the same number of attributes.
  • Corresponding attributes must have the same domain (data type).
  • Attribute names should be identical or similar in meaning.

🔹 Example (Bangladeshi Context)

Relation 1: Student_CSE

Student_IDNameDistrict
101Rafi AhmedDhaka
102Tanvir HasanRajshahi
103Imran HossainChattogram

Relation 2: Student_EEE

Student_IDNameDistrict
201Shanta RahmanKhulna
202Faisal KarimDhaka
103Imran HossainChattogram

🟩 Example 1: Simple Union

Operation:

Student_CSE ∪ Student_EEE

Result:

Student_IDNameDistrict
101Rafi AhmedDhaka
102Tanvir HasanRajshahi
103Imran HossainChattogram
201Shanta RahmanKhulna
202Faisal KarimDhaka

Explanation: The Union combines all students from both relations. Duplicate tuples (like Imran Hossain from Chattogram) appear only once in the result.


🟩 Example 2: Using Selection and Union Together

Operation:

District='Dhaka'(Student_CSE)) ∪ (σDistrict='Dhaka'(Student_EEE))

Result:

Student_IDNameDistrict
101Rafi AhmedDhaka
202Faisal KarimDhaka

Explanation: This query finds all students from Dhaka who are studying in either the CSE or EEE department.


🟩 Example 3: Projection Before Union

Operation:

πDistrict(Student_CSE) ∪ πDistrict(Student_EEE)

Result:

District
Dhaka
Rajshahi
Chattogram
Khulna

Explanation: The operation lists unique districts from which students belong across both departments.


🔹 Properties of Union

  • Commutative: R ∪ S = S ∪ R
  • Associative: (R ∪ S) ∪ T = R ∪ (S ∪ T)
  • Idempotent: R ∪ R = R
  • Duplicates are automatically removed.

🔹 SQL Equivalent

SELECT * FROM Student_CSE
UNION
SELECT * FROM Student_EEE;

🔹 Real-Life Use (Bangladesh Example)

  • Combining student lists from multiple departments in a university.
  • Merging employee records from different branches of a company in Dhaka and Chattogram.
  • Integrating supplier lists from two divisions (e.g., Rajshahi & Khulna).

✅ Summary Table

FeatureDescription
Operator∪ (Union)
PurposeCombine tuples from two relations
InputTwo union-compatible relations
OutputAll tuples from both relations (without duplicates)
SQL EquivalentUNION

relational algebra union operation, union example dbms, union operation bangladesh, relational algebra with bangladeshi data, union operator example, cse eee student data union, dbms union relational algebra

কোন মন্তব্য নেই:

একটি মন্তব্য পোস্ট করুন