Header Ads Widget

Join Operations

Join Operations:

A Join operation combines related tuples from different relations, if and only if a given join condition is satisfied. It is denoted by ⋈.

Example:

EMPLOYEE

EMP_CODEEMP_NAME
101Stephan
102Jack
103Harry

SALARY

EMP_CODESALARY
10150000
10230000
10325000
  1. Operation: (EMPLOYEE ⋈ SALARY)   

Result:

EMP_CODEEMP_NAMESALARY
101Stephan50000
102Jack30000
103Harry25000

Types of Join operations:


DBMS Join Operation

1. Natural Join:

  • A natural join is the set of tuples of all combinations in R and S that are equal on their common attribute names.
  • It is denoted by ⋈.

Example: Let's use the above EMPLOYEE table and SALARY table:

Input:

  1. ∏EMP_NAME, SALARY (EMPLOYEE ⋈ SALARY)  

Output:

EMP_NAMESALARY
Stephan50000
Jack30000
Harry25000

2. Outer Join:

The outer join operation is an extension of the join operation. It is used to deal with missing information.

Example:

EMPLOYEE

EMP_NAMESTREETCITY
RamCivil lineMumbai
ShyamPark streetKolkata
RaviM.G. StreetDelhi
HariNehru nagarHyderabad

FACT_WORKERS

EMP_NAMEBRANCHSALARY
RamInfosys10000
ShyamWipro20000
KuberHCL30000
HariTCS50000

Input:

  1. (EMPLOYEE ⋈ FACT_WORKERS)  

Output:

EMP_NAMESTREETCITYBRANCHSALARY
RamCivil lineMumbaiInfosys10000
ShyamPark streetKolkataWipro20000
HariNehru nagarHyderabadTCS50000

An outer join is basically of three types:

  1. Left outer join
  2. Right outer join
  3. Full outer join

a. Left outer join:

  • Left outer join contains the set of tuples of all combinations in R and S that are equal on their common attribute names.
  • In the left outer join, tuples in R have no matching tuples in S.
  • It is denoted by ⟕.

Example: Using the above EMPLOYEE table and FACT_WORKERS table

Input:

  1. EMPLOYEE ⟕ FACT_WORKERS   

EMP_NAMESTREETCITYBRANCHSALARY
RamCivil lineMumbaiInfosys10000
ShyamPark streetKolkataWipro20000
HariNehru streetHyderabadTCS50000
RaviM.G. StreetDelhiNULLNULL

b. Right outer join:

  • Right outer join contains the set of tuples of all combinations in R and S that are equal on their common attribute names.
  • In right outer join, tuples in S have no matching tuples in R.
  • It is denoted by ⟖.

Example: Using the above EMPLOYEE table and FACT_WORKERS Relation

Input:

  1. EMPLOYEE ⟖ FACT_WORKERS  

Output:

EMP_NAMEBRANCHSALARYSTREETCITY
RamInfosys10000Civil lineMumbai
ShyamWipro20000Park streetKolkata
HariTCS50000Nehru streetHyderabad
KuberHCL30000NULLNULL

c. Full outer join:

  • Full outer join is like a left or right join except that it contains all rows from both tables.
  • In full outer join, tuples in R that have no matching tuples in S and tuples in S that have no matching tuples in R in their common attribute name.
  • It is denoted by ⟗.

Example: Using the above EMPLOYEE table and FACT_WORKERS table

Input:

  1. EMPLOYEE ⟗ FACT_WORKERS  

Output:

EMP_NAMESTREETCITYBRANCHSALARY
RamCivil lineMumbaiInfosys10000
ShyamPark streetKolkataWipro20000
HariNehru streetHyderabadTCS50000
RaviM.G. StreetDelhiNULLNULL
KuberNULLNULLHCL30000

3. Equi join:

It is also known as an inner join. It is the most common join. It is based on matched data as per the equality condition. The equi join uses the comparison operator(=).

Example:

CUSTOMER RELATION

CLASS_IDNAME
1John
2Harry
3Jackson

PRODUCT

PRODUCT_IDCITY
1Delhi
2Mumbai
3Noida

Input:

  1. CUSTOMER ⋈ PRODUCT    

Output:

CLASS_IDNAMEPRODUCT_IDCITY
1John1Delhi
2Harry2Mumbai
3Harry3Noida

Post a Comment

0 Comments