DBMS Joins: THETA, Inner, Outer, Equi Types of Join
โก Smart opsummering
Join in DBMS is a binary operation that combines rows from two or more tables using their primary and foreign keys. Joins split into inner joins, which return only matching rows, and outer joins, which keep unmatched rows and fill gaps with null.

What is a Join in DBMS?
Deltag i DBMS is a binary operation that allows you to combine a join product and a selection in a single statement. The goal of creating a join condition is to combine the data from two or more tables. The tables are associated using their primary keys and udenlandske nรธgler.
Typer af tilslutning
Der er hovedsageligt to typer joinforbindelser i DBMS:
- Indre led: Theta, Natural, EQUI
- Outer Joins: Left, Right, Full
The table below previews all the join types before each is explained with an example.
| Bliv Medlem | Returpolitik | Unmatched rows |
|---|---|---|
| Inner (Theta / EQUI / Natural) | Rows matching the condition in both tables | Faldt |
| Left Outer | All left rows plus matches | Kept from left, null on right |
| Right Outer | All right rows plus matches | Kept from right, null on left |
| Full Outer | All rows from both tables | Kept from both, null where missing |
Indvendig sammenfรธjning
Indvendig sammenfรธjning is used to return rows from both tables that satisfy the given condition. It is the most widely used join operation and can be considered the default join type.
An inner join, or equijoin, is a comparator-based join that uses equality comparisons in the join predicate. However, if you use other comparison operators like โ>โ, it cannot be called an equijoin. Inner join is further divided into three subtypes:
- Theta slutter sig
- Naturlig sammenfรธjning
- EQUI tilslutte sig
Theta Deltag
Theta Deltag allows you to merge two tables based on the condition represented by theta. Theta joins work for all comparison operators. It is denoted by the symbol ฮธ. The general case of a JOIN operation is called a theta join.
Syntaks:
A โฮธ B
A theta join can use any conditions in the selection criteria.
Overvej fรธlgende tabeller.
| Tabel A | Tabel B | |||
|---|---|---|---|---|
| kolonne 1 | kolonne 2 | kolonne 1 | kolonne 2 | |
| 1 | 1 | 1 | 1 | |
| 1 | 2 | 1 | 3 | |
For eksempel:
A โ A.column 2 > B.column 2 (B)
| A โ A.kolonne 2 > B.kolonne 2 (B) | |
|---|---|
| kolonne 1 | kolonne 2 |
| 1 | 2 |
EQUI Deltag
EQUI Deltag 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 it is one reason why an RDBMS can have performance problems.
For eksempel:
A โ A.column 2 = B.column 2 (B)
| A โ A.kolonne 2 = B.kolonne 2 (B) | |
|---|---|
| kolonne 1 | kolonne 2 |
| 1 | 1 |
Natural Join (โ)
Naturlig Deltag does not use any comparison operator. In this type of join, the attributes should have the same name and domain. In a natural join, there should be at least one common attribute between the two relations.
It performs a selection forming equality on the attributes that appear in both relations and eliminates the duplicate attributes.
Eksempel: consider the following two tables.
| C | |
|---|---|
| I | Firkant |
| 2 | 4 |
| 3 | 9 |
| D | |
|---|---|
| I | Cube |
| 2 | 8 |
| 3 | 18 |
C โ D
| C โ D | ||
|---|---|---|
| I | Firkant | Cube |
| 2 | 4 | 8 |
| 3 | 9 | 18 |
Ydre tilslutning
An Ydre tilslutning does not require each record in the two joined tables to have a matching record. In this type of join, the table retains each record even if no other matching record exists. The three types of outer join are:
- Venstre ydre samling
- Hรธjre ydre samling
- Fuld ydre tilslutning
Venstre ydre samling (A โ B)
Venstre ydre samling returns all the rows from the table on the left, even if no matching rows are found in the table on the right. When no matching record is found on the right, null is returned.
Consider the following two tables.
| A | |
|---|---|
| I | Firkant |
| 2 | 4 |
| 3 | 9 |
| 4 | 16 |
| B | |
|---|---|
| I | Cube |
| 2 | 8 |
| 3 | 18 |
| 5 | 75 |
AB
| A โ B | ||
|---|---|---|
| I | Firkant | Cube |
| 2 | 4 | 8 |
| 3 | 9 | 18 |
| 4 | 16 | - |
Hรธjre ydre samling (A โ B)
Hรธjre ydre samling returns all the columns from the table on the right, even if no matching rows are found in the table on the left. Where no matches are found on the left, null is returned. A right outer join is the opposite of a left join.
AB
| A โ B | ||
|---|---|---|
| I | Cube | Firkant |
| 2 | 8 | 4 |
| 3 | 18 | 9 |
| 5 | 75 | - |
Fuld ydre sammenfรธjning (A โ B)
I en Fuld ydre tilslutning, alle tuples fra begge relationer er inkluderet i resultatet, uanset den matchende betingelse.
Eksempel:
AB
| A โ B | ||
|---|---|---|
| I | Firkant | Cube |
| 2 | 4 | 8 |
| 3 | 9 | 18 |
| 4 | 16 | - |
| 5 | - | 75 |


