Skip to main content

Joins in DBMS

DBMS Joins: Inner, THETA, Outer, Equi Types of Join Operations

Join in DBMS is a binary operation that allows you to combine join product and selection in one single statement. The goal of creating a join condition is that it helps you to combine the data from two or more DBMS tables. The tables in DBMS are associated using the primary key and foreign keys.

Types of Join

There are mainly two types of joins in DBMS:
  1. Inner Joins: Theta, Natural, EQUI
  2. 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.

Inner Join further divided into three subtypes:
  • Theta join
  • Natural join
  • EQUI join

Theta Join

Theta Join allows you to merge two tables based on the condition represented by theta. Theta joins work for all comparison operators. It is denoted by symbol θ. The general case of JOIN operation is called a Theta join.

Syntax:
A ⋈θ B

Theta join can use any conditions in the selection criteria.

Consider the following tables.

Table A

 

Table B

column 1

column 2

 

column 1

column 2

1

1

 

1

1

1

2

 

1

3


For example:

A  A.column 2 >  B.column 2 (B)

A  A.column 2 > B.column 2 (B)

column 1

column 2

1

2



EQUI Join

EQUI Join is done when a Theta join uses only the equivalence condition. EQUI join is the most difficult operation to implement efficiently in an RDBMS, and one reason why RDBMS have essential performance problems.

For example:

A  A.column 2 =  B.column 2 (B)

A  A.column 2 = B.column 2 (B)

column 1

column 2

1

1



Natural Join (⋈)

Natural Join does not utilize any of the comparison operators. In this type of join, the attributes should have the same name and domain. In Natural Join, there should be at least one common attribute between two relations.

It performs selection forming equality on those attributes which appear in both relations and eliminates the duplicate attributes.

Example:
Consider the following two tables

C

Num

Square

2

4

3

9

 

D

Num

Cube

2

8

3

18

C  D

C  D

Num

Square

Cube

2

4

8

3

9

18



Outer Join

An Outer Join doesn’t require each record in the two join tables to have a matching record. In this type of join, the table retains each record even if no other matching record exists.

Three types of Outer Joins are:
  • Left Outer Join
  • Right Outer Join
  • Full Outer Join

Left Outer Join (A B)

Left Outer Join returns all the rows from the table on the left even if no matching rows have been found in the table on the right. When no matching record is found in the table on the right, NULL is returned.



Consider the following 2 Tables

A

Num

Square

2

4

3

9

4

16

 

B

Num

Cube

2

8

3

18

5

75

A  B

A  B

Num

Square

Cube

2

4

8

3

9

18

4

16



Right Outer Join ( A B )

Right Outer Join returns all the columns from the table on the right even if no matching rows have been found in the table on the left. Where no matches have been found in the table on the left, NULL is returned. RIGHT outer JOIN is the opposite of LEFT JOIN

In our example, let’s assume that you need to get the names of members and movies rented by them. Now we have a new member who has not rented any movies yet.




A  B

A  B

Num

Cube

Square

2

8

4

3

18

9

5

75


Full Outer Join ( A B)

In a Full Outer Join, all tuples from both relations are included in the result, irrespective of the matching condition.

Example:

A  B

A  B

Num

Square

Cube

2

4

8

3

9

18

4

16

5

75


Comments

Popular posts from this blog

Natural Language Processing (NLP)

What is Natural Language Processing (NLP) ? Natural Language Processing (NLP)* is a field of artificial intelligence (AI) that focuses on the interaction between computers and humans using natural language. It involves the development of algorithms and models that enable computers to understand, interpret, and generate human language. Here are key aspects of NLP: 1. *Text Understanding:* NLP systems aim to comprehend the meaning of written or spoken language. This involves tasks such as text classification, sentiment analysis, and named entity recognition. 2. *Speech Recognition:* NLP extends to processing spoken language, converting audio signals into text. This technology is used in voice assistants, transcription services, and more. 3. *Language Generation:* NLP systems can generate human-like text. This is employed in chatbots, language translation services, and content generation. 4. *Machine Translation:* NLP is fundamental to machine translation systems that enable the automatic...

JS Code for Generating OTP

JS Code for Generating OTP -  * Learn how to create a simple JavaScript function to generate a random 4-digit OTP. (GENERATED BY - ChatGPT) function OTP() { let otp = ""; otp = Math.floor(Math.random() * 9000 + 1000); return otp; } console.log("Your OTP is-", OTP());

How To Make Symbols With Keyboard

HOW TO MAKE SYMBOLS WITH A KEYBOARD (Image By - Sharma Guides | Subham232330) Alt + 0153 :   ™  (trademark symbol) Alt + 0169 :   ©  (copyright symbol) Alt + 0174 :   ®  (registered trademark symbol) Alt + 0176 :   °  (degree symbol) Alt + 0177 :  ±  (plus-or-minus sign) Alt + 0182 :   ¶  (paragraph mark) Alt + 0190 :   ¾  (fraction, three-fourths) Alt + 0215 :   × (multiplication sign) Alt + 0162 :   ¢  (thecent sign) Alt + 0161 :   ¡  (upside down exclamation point) Alt + 0191 :   ¿  (upside down question mark) Alt + 1 : ☺ (smiley face) Alt + 2 :   ☻ (black smiley face) Alt + 15 :   ☼  (Sun) Alt + 12 :   ♀  (female sign) Alt + 11 :   ♂  (male sign) Alt + 6 :   ♠  (spade) Alt + 5 :   ♣  (Club) Alt + 3 :   ♥  (Heart) Alt + 4 :   ♦  (Diamond) Alt + 13 :   ♪  (eighth note...