What is join operation in relational algebra (DBMS)?

DBMSDatabaseBig Data Analytics

Join operation combines the relation R1 and R2 with respect to a condition. It is denoted by ⋈.

The different types of join operation are as follows −

  • Theta join

  • Natural join

  • Outer join − It is further classified into following types −

    • Left outer join.

    • Right outer join.

    • Full outer join.

Theta join

If we join R1 and R2 other than the equal to condition then it is called theta join/ non-equi join.

Example

Consider R1 table

RegNoBranchSection
1CSEA
2ECEB
3CIVILA
4ITB
5ITA

Table R2

NameRegNo
Bhanu2
Priya4

R1 ⋈ R2 with condition R1.regno > R2.regno

RegNoBranchSectionNameRegno
3CIVILABhanu2
4ITBBhanu2
5ITABhanu2
5ITBPriya4

In the join operation, we select those rows from the cartesian product where R1.regno>R2.regno.

Join operation = select operation + cartesian product operation

Natural join

If we join R1 and R2 on equal condition then it is called natural join or equi join. Generally, join is referred to as natural join.

Natural join of R1 and R2 is −

{ we select those tuples from cartesian product where R1.regno=R2.regno}

R1 ⋈ R2

RegnoBranchSectionName
2--Bhanu
4--priya

Outer join

It is an extension of natural join to deal with missing values of relation.

Consider R1 and R2 shown below −

Table R1

RegNoBranchSection
1CSEA
2ECEB
3CIVILA
4ITB
5ITA

Table R2

NameRegno
Bhanu2
Priya4
Hari7

Outer join is of three types. These are explained below −

Left outer join

It is denoted by R1 ⋈ R2.

RegNoBranchSectionNameRegno
2--Bhanu2
4--Priya4
1--NULLNULL
3--NULLNULL
5--NULLNULL

Here all the tuples of R1(left table) appear in output.

The mismatching values of R2 are filled with NULL.

Left outer join = natural join + mismatch / extra tuple of R1

Right outer join

It is denoted by R1 ⋈ R2

Here all the tuples of R2(right table) appear in output. The mismatching values of R1 are filled with NULL.

RegNoBranchSectionNameRegno
2--Bhanu2
4--Priya4
NULLNULLNULLHari7

Right outer join = natural join+ mismatch/extra tuple of R2.

Full outer join

It is denoted by R1 ⋈ R2.

Full outer join=left outer join U right outer join.

RegNoBranchSectionNameRegno
2--Bhanu2
4--Priya4
1--NULLNULL
3--NULLNULL
5--NULLNULL
NULLNULLNULLHari7

Example

Given below is the picture of full outer join −

raja
Published on 06-Jul-2021 14:31:41
Advertisements