Completing the Picture - FULL JOIN Mastery
Introduction to FULL JOIN
Welcome back! By now, you are familiar with different types of SQL joins, such as INNER JOIN, LEFT JOIN, and RIGHT JOIN. Today, we will dive into another powerful join operation known as FULL JOIN.
A FULL JOIN combines the results of both LEFT JOIN and RIGHT JOIN. This means it returns all rows when there is a match in one of the tables, as well as rows that do not have a match in either table. It fills in NULL values for columns from the table lacking corresponding rows. Essentially, a FULL JOIN gives you a complete picture of data from two tables.
Dataset Refresher
To give you a quick reminder, here are the three tables we are using:
Movies Table
| movie_id | movie_name |
|---|---|
| 1 | Iron Man |
| 2 | The Incredible Hulk |
| 3 | Captain America: The First Avenger |
| 4 | The Avengers |
Movie Details Table
| movie_id | imdb_rating | box_office_million_usd |
|---|---|---|
| 1 | 7.9 | 585.2 |
| 3 | 6.9 | 370.6 |
| 4 | 8.0 | 1519.6 |
Characters Table
| character_id | movie_id | character_name |
|---|---|---|
| 1 | 1 | Tony Stark/Iron Man |
| 2 | 1 | Pepper Potts |
| 3 | 1 | James Rhodes |
| 4 | 1 | Obadiah Stane |
| 5 | 3 | Steve Rogers/Captain America |
| 6 | 3 | Peggy Carter |
| 7 | 3 | Bucky Barnes/Winter Soldier |
| 8 | 3 | Johann Schmidt/Red Skull |
| 9 | 3 | Howard Stark |
| 10 | 4 | Steve Rogers/Captain America |
| 11 | 4 | Tony Stark/Iron Man |
| 12 | 4 | Thor |
| 13 | 4 | Natasha Romanoff/Black Widow |
| 14 | 4 | Bruce Banner/Hulk |
| 15 | 4 | Clint Barton/Hawkeye |
| 16 | 4 | Loki |
| 17 | 5 | T'challa |
