Today I explored SQL Joins – one of the most important concepts in relational databases and also practiced with some coding problems on HackerRank.
Types of Joins
- INNER JOIN → Returns only the matching rows from both tables.
- LEFT JOIN → Returns all rows from the left table + matched rows from the right table.
- RIGHT JOIN → Returns all rows from the right table + matched rows from the left table.
- FULL JOIN (or OUTER JOIN) → Returns all rows when there is a match in one of the tables.
Among these, the most commonly used is the INNER JOIN.
✅ INNER JOIN Example
Let’s say we have two tables:
movies
| movie_id | movie_name |
|---|---|
| 1 | Ghajini |
| 2 | Singam |
| 3 | Kaakha Kaakha |
actors
| actor_id | actor_name |
|---|---|
| 1 | Surya |
| 2 | Asin |
| 3 | Jyothika |
movie_actors
| movie_id | actor_id |
|---|---|
| 1 | 1 |
| 1 | 2 |
| 3 | 1 |
| 3 | 3 |
📝 Query (INNER JOIN)
SELECT m.movie_name, a.actor_name
FROM movies m
INNER JOIN movie_actors ma ON m.movie_id = ma.movie_id
INNER JOIN actors a ON ma.actor_id = a.actor_id;
Output
| movie_name | actor_name |
|---|---|
| Ghajini | Surya |
| Ghajini | Asin |
| Kaakha Kaakha | Surya |
| Kaakha Kaakha | Jyothika |




Top comments (0)