Join in DBMS
Join in DBMS
Topperworld.in
Join in dbms
⚫ The main purpose of Join is to retrieve the data from multiple tables in
other words Join is used to perform multi-table query. It is denoted by ⨝.
Syntax:
where R1 and R2 are two relations to be join and R3 is a relation that will holds
the result of join operation.
Example:
Temp <- ⨝(student) S.roll==E.roll(Exam)
❖ Types of Join
1) Inner Join
2) Outer join
©Topperworld
DBMS
❖ Inner join
Inner Join is a join operation in DBMS that combines two or more table based
on related columns and return only rows that have matching values among
tables.Inner join of two types.
1) Equi Join
2) Natural Join
➢ Equi join
Example:
CUSTOMER RELATION
CLASS_ID NAME
1 John
2 Harry
3 Jackson
©Topperworld
DBMS
PRODUCT
PRODUCT_ID CITY
1 Delhi
2 Mumbai
3 Noida
Input:
CUSTOMER ⋈ PRODUCT
Output:
1 John 1 Delhi
2 Harry 2 Mumbai
3 Harry 3 Noida
©Topperworld
DBMS
➢ 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:
Output:
EMP_NAME SALARY
Stephan 50000
Jack 30000
Harry 25000
©Topperworld
DBMS
❖ Outer Join
The outer join operation is an extension of the join operation. It is used to deal
with missing information.
Example:
EMPLOYEE
FACT_WORKERS
©Topperworld
DBMS
Input:
(EMPLOYEE ⋈ FACT_WORKERS)
Output:
➢ Left outer join contains the set of tuples of all combinations in R and S that
are equal on their common attribute names.
➢ It is denoted by ⟕.
©Topperworld
DBMS
Input:
EMPLOYEE ⟕ FACT_WORKERS
➢ Right outer join contains the set of tuples of all combinations in R and S that
are equal on their common attribute names.
➢ It is denoted by ⟖.
Input:
EMPLOYEE ⟖ FACT_WORKERS
©Topperworld
DBMS
Output:
ADVERTISEMENT
➢ 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 ⟗.
Input:
EMPLOYEE ⟗ FACT_WORKERS
©Topperworld
DBMS
Output:
©Topperworld