Relational Algebra – Join (⨝) Operation in DBMS

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_IDNameDepartment_IDDistrict
101Rafi Ahmed10Dhaka
102Shanta Rahman20Khulna
103Tanvir Hasan10Rajshahi
104Sumaiya Akter30Dhaka
105Imran Hossain10Chattogram

Relation 2: Department

Department_IDDepartment_NameBuilding
10CSEMain Building
20EEEScience Block
30BBABusiness Complex

🟩 Example 1: Natural Join

Operation:

Student ⨝ Department

Result:

Student_IDNameDepartment_IDDistrictDepartment_NameBuilding
101Rafi Ahmed10DhakaCSEMain Building
102Shanta Rahman20KhulnaEEEScience Block
103Tanvir Hasan10RajshahiCSEMain Building
104Sumaiya Akter30DhakaBBABusiness Complex
105Imran Hossain10ChattogramCSEMain 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_IDNameStudent.Department_IDDistrictDepartment.Department_IDDepartment_NameBuilding
101Rafi Ahmed10Dhaka10CSEMain Building
102Shanta Rahman20Khulna20EEEScience Block
103Tanvir Hasan10Rajshahi10CSEMain Building
104Sumaiya Akter30Dhaka30BBABusiness Complex
105Imran Hossain10Chattogram10CSEMain Building

🟩 Example 4: Join with Selection and Projection

Operation:

πName, Department_Name, DistrictDepartment_Name='CSE'(Student ⨝ Department))

Result:

NameDepartment_NameDistrict
Rafi AhmedCSEDhaka
Tanvir HasanCSERajshahi
Imran HossainCSEChattogram

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

FeatureDescription
Operator⨝ (Join)
PurposeCombine data from multiple relations
InputTwo relations
OutputCombined relation with related data
SQL EquivalentJOIN ... 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

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

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