You are on page 1of 2

DBMS - Joins

We underst and t he benefit s of t aking a Cart esian product of t wo relat ions, which gives us all t he
possible t uples t hat are paired t oget her. But it might not be feasible for us in cert ain cases t o t ake a
Cart esian product where we encount er huge relat ions wit h t housands of t uples having a considerable
large number of at t ribut es.

Join is a combinat ion of a Cart esian product followed by a select ion process. A Join operat ion pairs
t wo t uples from different relat ions, if and only if a given join condit ion is sat isfied.

We will briefly describe various join t ypes in t he following sect ions.

Theta (θ) Join


Thet a join combines t uples from different relat ions provided t hey sat isfy t he t het a condit ion. The
join condit ion is denot ed by t he symbol θ .

Notation

R1 ⋈θ R2

R1 and R2 are relat ions having at t ribut es (A1, A2, .., An) and (B1, B2,.. ,Bn) such t hat t he at t ribut es
don’t have anyt hing in common, t hat is R1 ∩ R2 = Φ.

Thet a join can use all kinds of comparison operat ors.

St udent _ Det ail −

STUDENT ⋈Student.Std = Subject.Class SUBJECT

Equijoin
When Thet a join uses only equality comparison operat or, it is said t o be equijoin. The above example
corresponds t o equijoin.
Natural Join (⋈)
Nat ural join does not use any comparison operat or. It does not concat enat e t he way a Cart esian
product does. We can perform a Nat ural Join only if t here is at least one common at t ribut e t hat
exist s bet ween t wo relat ions. In addit ion, t he at t ribut es must have t he same name and domain.

Nat ural join act s on t hose mat ching at t ribut es where t he values of at t ribut es in bot h t he relat ions
are same.

Outer Joins
Thet a Join, Equijoin, and Nat ural Join are called inner joins. An inner join includes only t hose t uples wit h
mat ching at t ribut es and t he rest are discarded in t he result ing relat ion. Therefore, we need t o use
out er joins t o include all t he t uples from t he part icipat ing relat ions in t he result ing relat ion. There are
t hree kinds of out er joins − left out er join, right out er join, and full out er join.

Left Outer Join(R S)


All t he t uples from t he Left relat ion, R, are included in t he result ing relat ion. If t here are t uples in R
wit hout any mat ching t uple in t he Right relat ion S, t hen t he S-at t ribut es of t he result ing relat ion are
made NULL.

Right Outer Join: ( R S)


All t he t uples from t he Right relat ion, S, are included in t he result ing relat ion. If t here are t uples in S
wit hout any mat ching t uple in R, t hen t he R-at t ribut es of result ing relat ion are made NULL.

Full Outer Join: ( R S)


All t he t uples from bot h part icipat ing relat ions are included in t he result ing relat ion. If t here are no
mat ching t uples for bot h relat ions, t heir respect ive unmat ched at t ribut es are made NULL.

You might also like