---Advertisement---

MySQL JOINS Tutorial: A Complete Guide with Examples Great 2025

By Manisha

Updated On:

---Advertisement---
MySQL JOINS Tutorial

MySQL JOINS Tutorial: MySQL JOINS are used to retrieve data from multiple tables based on a related column between them. They are essential for combining information efficiently, reducing redundancy, and improving performance compared to subqueries.

  • MySQL JOINS Tutorial: Performance Boost: Joins utilize indexing, reducing query execution time.
  • Efficiency: A single JOIN query replaces multiple SELECT statements, reducing database load.
  • Simplified Query Logic: Eliminates the need for complex data manipulations in the application layer.

1. INNER JOIN (Most Commonly Used)

Returns only the matching rows from both tables.

Example: Fetch members who rented a movie along with the movie title.

sql

SELECT members.first_name, members.last_name, movies.title 

FROM members 

INNER JOIN movies 

ON members.movie_id = movies.id;

Output:

first_namelast_nametitle
AdamSmithASSASSIN’S CREED: EMBERS
RaviKumarReal Steel (2012)
SusanDavidsonSafe (2012)

2. LEFT JOIN (All Records from Left Table, Matches from Right)

MySQL JOINS Tutorial: Returns all rows from the left table and matching rows from the right table. If there is no match, NULL values are returned.

Example: Fetch all movies and the members who rented them.

sql

SELECT movies.title, members.first_name, members.last_name 

FROM movies 

LEFT JOIN members 

ON movies.id = members.movie_id;

Output:

titlefirst_namelast_name
ASSASSIN’S CREED: EMBERSAdamSmith
Alvin and the ChipmunksNULLNULL

3. RIGHT JOIN (All Records from Right Table, Matches from Left)

MySQL JOINS Tutorial: Works like LEFT JOIN but returns all rows from the right table and only matching records from the left table.

Example: Fetch members and the movies they rented, including members who haven’t rented any movies.

sql

SELECT members.first_name, members.last_name, movies.title 

FROM members 

RIGHT JOIN movies 

ON movies.id = members.movie_id;

Output:

first_namelast_nametitle
AdamSmithASSASSIN’S CREED: EMBERS
NULLNULLAlvin and the Chipmunks

4. CROSS JOIN (All Possible Combinations)

MySQL JOINS Tutorial: Each row from the first table is combined with every row from the second table.

Example: Generate a combination of all members with all movies.

sql

SELECT members.first_name, movies.title 

FROM members 

CROSS JOIN movies;

Output:

first_nametitle
AdamASSASSIN’S CREED: EMBERS
AdamReal Steel (2012)
AdamSafe (2012)

  • ON Clause: Used when column names differ.
  • USING Clause: Used when the column name is the same in both tables.

Example Using USING Clause:

sql

SELECT movies.title, members.first_name 

FROM movies 

LEFT JOIN members 

USING (movie_id);


✅ Use INNER JOIN when you only need matching records.
✅ Use LEFT/RIGHT JOIN when dealing with optional data.
✅ Prefer JOINs over subqueries for better performance.
✅ Use proper indexing on the foreign key column.


MySQL JOINS are essential for working with relational databases efficiently. By understanding INNER, LEFT, RIGHT, and CROSS JOINs, you can improve query performance and database management.

Got questions? Drop them in the comments! 

MYSQL SUBQUERY Tutorial

Download My SQL

Leave a Comment

Index