Consider the following tables:
| EmployeeId | Name |
|---|---|
| 1 | Alice |
| 2 | Bob |
| 3 | Carol |
| TaskId | EmployeeId | TaskName |
|---|---|---|
| 101 | 1 | Task A |
| 102 | 2 | Task B |
| 103 | 2 | Task C |
| 104 | 4 | Task D |
An INNER JOIN returns only the rows where there is a match
between the two tables.
| EmployeeName | TaskName |
|---|---|
| Alice | Task A |
| Bob | Task B |
| Bob | Task C |
Number of Rows: 3
A LEFT JOIN returns all rows from the left table, with
matching rows from the right table. If there is no match, the result is
NULL on the right side.
| EmployeeName | TaskName |
|---|---|
| Alice | Task A |
| Bob | Task B |
| Bob | Task C |
| Carol | NULL |
Number of Rows: 4
A RIGHT JOIN returns all rows from the right table, with
matching rows from the left table. If there is no match, the result is
NULL on the left side.
| EmployeeName | TaskName |
|---|---|
| Alice | Task A |
| Bob | Task B |
| Bob | Task C |
| NULL | Task D |
Number of Rows: 4
A FULL JOIN returns all rows when there is a match in one of
the tables. It combines the results of both LEFT JOIN and
RIGHT JOIN.
| EmployeeName | TaskName |
|---|---|
| Alice | Task A |
| Bob | Task B |
| Bob | Task C |
| Carol | NULL |
| NULL | Task D |
Number of Rows: 5