Relational Algebra Operations – Join (⨝)
The Join Operation in Relational Algebra is used to combine related tuples (rows) from two or more relations (tables) based on a common attribute.
It merges data from different tables to produce a meaningful and unified result.
In SQL, this is similar to the JOIN clause.
🔹 Definition
Join is a binary operation (it works on two relations). It connects tuples of one relation with tuples of another relation when they share a common attribute.
Notation:
R ⨝ S
General Form:
R ⨝condition S
Here, R and S are two relations (tables), and the join condition defines how tuples are matched.
🔹 Example (Bangladeshi University Dataset)
Relation 1: Student
| Student_ID | Name | Department_ID | District |
|---|---|---|---|
| 101 | Rafi Ahmed | 10 | Dhaka |
| 102 | Shanta Rahman | 20 | Khulna |
| 103 | Tanvir Hasan | 10 | Rajshahi |
| 104 | Sumaiya Akter | 30 | Dhaka |
| 105 | Imran Hossain | 10 | Chattogram |
Relation 2: Department
| Department_ID | Department_Name | Building |
|---|---|---|
| 10 | CSE | Main Building |
| 20 | EEE | Science Block |
| 30 | BBA | Business Complex |
🟩 Example 1: Natural Join
Operation:
Student ⨝ Department
Result:
| Student_ID | Name | Department_ID | District | Department_Name | Building |
|---|---|---|---|---|---|
| 101 | Rafi Ahmed | 10 | Dhaka | CSE | Main Building |
| 102 | Shanta Rahman | 20 | Khulna | EEE | Science Block |
| 103 | Tanvir Hasan | 10 | Rajshahi | CSE | Main Building |
| 104 | Sumaiya Akter | 30 | Dhaka | BBA | Business Complex |
| 105 | Imran Hossain | 10 | Chattogram | CSE | Main Building |
Explanation: The Department_ID column is common in both tables. The Natural Join automatically matches tuples with the same Department_ID.
🟩 Example 2: Theta Join (Conditional Join)
Operation:
Student ⨝Student.Department_ID = Department.Department_ID Department
Result: Same as the natural join, since we manually specify the matching condition.
🟩 Example 3: Equi Join
An Equi Join is a type of Theta Join that uses only equality (=) conditions. It produces a larger table containing duplicate columns for the join attribute.
Operation:
Student ⨝Student.Department_ID = Department.Department_ID Department
Result:
| Student_ID | Name | Student.Department_ID | District | Department.Department_ID | Department_Name | Building |
|---|---|---|---|---|---|---|
| 101 | Rafi Ahmed | 10 | Dhaka | 10 | CSE | Main Building |
| 102 | Shanta Rahman | 20 | Khulna | 20 | EEE | Science Block |
| 103 | Tanvir Hasan | 10 | Rajshahi | 10 | CSE | Main Building |
| 104 | Sumaiya Akter | 30 | Dhaka | 30 | BBA | Business Complex |
| 105 | Imran Hossain | 10 | Chattogram | 10 | CSE | Main Building |
🟩 Example 4: Join with Selection and Projection
Operation:
πName, Department_Name, District(σDepartment_Name='CSE'(Student ⨝ Department))
Result:
| Name | Department_Name | District |
|---|---|---|
| Rafi Ahmed | CSE | Dhaka |
| Tanvir Hasan | CSE | Rajshahi |
| Imran Hossain | CSE | Chattogram |
Explanation: This query joins both tables, filters rows where the department is CSE, and then displays only Name, Department_Name, and District.
🔹 Types of Join in Relational Algebra
- Natural Join (⨝): Joins automatically using common attributes.
- Theta Join: Joins using a specified condition (>, <, =, etc.).
- Equi Join: A Theta Join that uses equality only.
- Outer Join: Includes unmatched tuples as well (Left, Right, Full).
🔹 SQL Equivalent
SELECT * FROM Student JOIN Department ON Student.Department_ID = Department.Department_ID;
🔹 Real-Life Use (Bangladesh Example)
- Combining student records with department details in a university database.
- Generating a list of students and their faculty buildings.
- Joining teacher and course tables to prepare teaching load reports.
✅ Summary Table
| Feature | Description |
|---|---|
| Operator | ⨝ (Join) |
| Purpose | Combine data from multiple relations |
| Input | Two relations |
| Output | Combined relation with related data |
| SQL Equivalent | JOIN ... ON |
relational algebra join operation, natural join in dbms, equi join example, theta join, relational algebra with bangladeshi dataset, student and department join example, dbms join operation tutorial
কোন মন্তব্য নেই:
একটি মন্তব্য পোস্ট করুন