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_ID | Name | District |
|---|---|---|
| 101 | Rafi Ahmed | Dhaka |
| 102 | Tanvir Hasan | Rajshahi |
| 103 | Imran Hossain | Chattogram |
Relation 2: Student_EEE
| Student_ID | Name | District |
|---|---|---|
| 201 | Shanta Rahman | Khulna |
| 202 | Faisal Karim | Dhaka |
| 103 | Imran Hossain | Chattogram |
🟩 Example 1: Simple Union
Operation:
Student_CSE ∪ Student_EEE
Result:
| Student_ID | Name | District |
|---|---|---|
| 101 | Rafi Ahmed | Dhaka |
| 102 | Tanvir Hasan | Rajshahi |
| 103 | Imran Hossain | Chattogram |
| 201 | Shanta Rahman | Khulna |
| 202 | Faisal Karim | Dhaka |
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_ID | Name | District |
|---|---|---|
| 101 | Rafi Ahmed | Dhaka |
| 202 | Faisal Karim | Dhaka |
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
| Feature | Description |
|---|---|
| Operator | ∪ (Union) |
| Purpose | Combine tuples from two relations |
| Input | Two union-compatible relations |
| Output | All tuples from both relations (without duplicates) |
| SQL Equivalent | UNION |
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
কোন মন্তব্য নেই:
একটি মন্তব্য পোস্ট করুন