Joining Tables - SQL JOINs with PostgreSQL
Introduction to SQL JOINs
Welcome to the lesson on SQL JOINs with PostgreSQL! So far, you’ve learned how to retrieve data using basic SQL queries. Now, we’ll explore how to combine data from multiple tables, which is crucial for complex database querying and analysis.
Dataset Overview
In this lesson, we’ll use a simplified version of the Marvel movies dataset. Here’s a look at the simplified tables.
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 |
In order to link these tables together, we will use the movie_id key which is present in all 3 tables. Let’s dive in and explore how to use different types of JOINs to combine these tables effectively.

