0% found this document useful (0 votes)
96 views15 pages

Join

Relational algebra uses joins to combine tuples from two relations based on a join condition. The main types of joins are inner joins (which return only matching tuples) like theta, natural, and equi joins and outer joins (which return all tuples from one or both relations) like left, right, and full outer joins. Inner joins include tuples that satisfy the join condition while outer joins include all tuples by replacing missing values with NULL.

Uploaded by

Shantanu Dash
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
96 views15 pages

Join

Relational algebra uses joins to combine tuples from two relations based on a join condition. The main types of joins are inner joins (which return only matching tuples) like theta, natural, and equi joins and outer joins (which return all tuples from one or both relations) like left, right, and full outer joins. Inner joins include tuples that satisfy the join condition while outer joins include all tuples by replacing missing values with NULL.

Uploaded by

Shantanu Dash
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 15

Relational Algebra

JOIN
Join
Join is a combination of a Cartesian product
followed by a selection process. A Join operation
pairs two tuples from different relations, if and
only if a given join condition is satisfied.
Types of Join
• There are mainly two types of joins in DBMS:
• Inner Joins: Theta, Natural, EQUI
• Outer Join: Left, Right, Full
• Inner Join
• Inner Join is used to return rows from both
tables which satisfy the given condition. It is the
most widely used join operation and can be
considered as a default join-type
• An Inner join or equijoin is a comparator-based
join which uses equality comparisons in the join-
predicate. However, if you use other comparison
operators like “>” it can’t be called equijoin.
Theta (θ) Join

• Theta join combines tuples from different relations


provided they satisfy the theta condition.
• The join condition is denoted by the symbol θ.
• Notation
• R1 ⋈θ R2
• R1 and R2 are relations having attributes (A1, A2, ..,
An) and (B1, B2,.. ,Bn) such that the attributes don’t
have anything in common, that is R1 ∩ R2 = Φ.
• Theta join can use all kinds of comparison operators.
example
Subjects
Student
Class Subject
SID Name Std
10 Math
101 Alex 10
10 English
102 Maria 11
11 Music

11 Sports

Student_Detail − Student_detail

SID Name Std Class Subject


STUDENT ⋈Student.Std = Subject.Class SUBJECT
101 Alex 10 10 Math

101 Alex 10 10 English

102 Maria 11 11 Music

102 Maria 11 11 Sports


Equijoin

• When Theta join uses


only equality comparison operator, it is said to
be equijoin. The previous example
corresponds to equijoin.
Natural Join (⋈)

• Natural join does not use any comparison operator.


• It does not concatenate the way a Cartesian product
does.
• We can perform a Natural Join only if there is at least
one common attribute that exists between two
relations.
• In addition, the attributes must have the same name
and domain.
• Natural join acts on those matching attributes where
the values of attributes in both the relations are same.
example
Courses HoD

CID Course Dept Dept Head

CS01 Database CS CS Alex

ME01 Mechanics ME ME Maya

EE01 Electronics EE EE Mira

Courses ⋈ HoD

Dept CID Course Head

CS CS01 Database Alex

ME ME01 Mechanics Maya

EE EE01 Electronics Mira


Outer Joins

• Theta Join, Equijoin, and Natural Join are called


inner joins.
• An inner join includes only those tuples with
matching attributes and the rest are discarded in
the resulting relation. Therefore, we need to use
outer joins to include all the tuples from the
participating relations in the resulting relation.
• There are three kinds of outer joins −
– left outer join,
– right outer join, and
– full outer join.
Left Outer Join
• Left Outer Join(R   S)
• All the tuples from the Left relation, R, are
included in the resulting relation. If there are
tuples in R without any matching tuple in the
Right relation S, then the S-attributes of the
resulting relation are made NULL.
Example

Left Right

A B A B

100 Database 100 Alex

101 Mechanics 102 Maya

102 Electronics 104 Mira

Courses    HoD

A B C D

100 Database 100 Alex

101 Mechanics --- ---

102 Electronics 102 Maya


Right Outer Join
• Right Outer Join: ( R   S )
• All the tuples from the Right relation, S, are
included in the resulting relation. If there are
tuples in S without any matching tuple in R,
then the R-attributes of resulting relation are
made NULL.
example

Courses   HoD

A B C D

100 Database 100 Alex

102 Electronics 102 Maya

--- --- 104 Mira


Full Outer Join
• Full Outer Join: ( R   S)
• All the tuples from both participating relations
are included in the resulting relation. If there
are no matching tuples for both relations,
their respective unmatched attributes are
made NULL.
Example

Courses     HoD

A B C D

100 Database 100 Alex

101 Mechanics --- ---

102 Electronics 102 Maya

--- --- 104 Mira

You might also like