DBMS Joins: Theta (θ) join
DBMS Joins: Theta (θ) join
DBMS Joins: Theta (θ) join
We understand the benefits of Cartesian product of two relation, which gives us all the possible tuples that are paired
together. But Cartesian product might not be feasible for huge relations where number of tuples are in thousands and
the attributes of both relations are considerable large.
Join is combination of Cartesian product followed by selection process. Join operation pairs two tuples from different
relations if and only if the given join condition is satisfied.
Notation:
R1 ⋈θ R2
R1 and R2 are relations with their attributes (A1, A2, .., An ) and (B1, B2,.. ,Bn) such that no attribute matches that is
R1 ∩ R2 = Φ Here θ is condition in form of set of conditions C.
Student
101 Alex 10
102 Maria 11
Subjects
Class Subject
10 Math
10 English
11 Music
11 Sports
Student_Detail =
STUDENT ⋈Student.Std = Subject.Class SUBJECT
Student_detail
Equi-Join
When Theta join uses only equality comparison operator it is said to be Equi-Join. The above example conrresponds
to equi-join
Natural Join ( ⋈)
Natural join does not use any comparison operator. It does not concatenate the way Cartesian product does. Instead,
Natural Join can only be performed if the there is at least one common attribute exists between relation. Those
attributes must have same name and domain.
Natural join acts on those matching attributes where the values of attributes in both relation is same.
Courses
CS01 Database CS
ME01 Mechanics ME
EE01 Electronics EE
HoD
Dept Head
CS Alex
ME Maya
EE Mira
Courses ⋈ HoD
Outer Joins
All joins mentioned above, that is Theta Join, Equi Join and Natural Join are called inner-joins. An inner-join process
includes only tuples with matching attributes, rest are discarded in resulting relation. There exists methods by which
all tuples of any relation are included in the resulting relation.
Left
A B
100 Database
101 Mechanics
102 Electronics
Right
A B
100 Alex
102 Maya
104 Mira
Courses HoD
A B C D
Courses HoD
A B C D
Courses HoD
A B C D
100 Database 100 Alex
Source:
http://www.tutorialspoint.com/dbms/database_joins.htm