(INNER, LEFT, RIGHT & FULL JOIN)
When building real-world applications in Laravel, working with multiple database tables is unavoidable.
Whether you’re creating dashboards, APIs, or reports, you’ll often need to fetch related data efficiently.
This is where Laravel joins become essential.
In this guide, I’ll explain INNER JOIN, LEFT JOIN, RIGHT JOIN, and FULL JOIN in Laravel using simple tables, SQL logic, and clean Query Builder examples—so even beginners can understand them easily.
A join allows you to combine rows from two or more database tables based on a related column.
Laravel provides an elegant way to write joins using the Query Builder, making queries readable and easy to maintain.
To keep things simple, we’ll use two tables.
| id | name |
|---|---|
| 1 | Rahul |
| 2 | Amit |
| 3 | Neha |
| id | user_id | title |
|---|---|---|
| 1 | 1 | Laravel Tips |
| 2 | 1 | PHP Basics |
| 3 | 2 | JavaScript |
| 4 | 4 | Python |
user_id = 4 does not exist in the users tableThese cases help explain how each join behaves.
INNER JOIN returns only records that exist in both tables.
If there’s no match on either side, the record is excluded.
SELECT users.name, posts.title
FROM users
INNER JOIN posts ON users.id = posts.user_id;
$data = DB::table('users')
->join('posts', 'users.id', '=', 'posts.user_id')
->select('users.name', 'posts.title')
->get();
| name | title |
|---|---|
| Rahul | Laravel Tips |
| Rahul | PHP Basics |
| Amit | JavaScript |
❌ Neha is missing (no posts)
❌ Python post is missing (invalid user)
LEFT JOIN returns all records from the left table, even if no matching record exists in the right table.
Missing values are returned as NULL.
SELECT users.name, posts.title
FROM users
LEFT JOIN posts ON users.id = posts.user_id;
$data = DB::table('users')
->leftJoin('posts', 'users.id', '=', 'posts.user_id')
->select('users.name', 'posts.title')
->get();
| name | title |
|---|---|
| Rahul | Laravel Tips |
| Rahul | PHP Basics |
| Amit | JavaScript |
| Neha | NULL |
✅ Neha appears even though she has no posts
RIGHT JOIN returns all records from the right table, even if no matching record exists in the left table.
⚠️ MySQL supports RIGHT JOIN, and Laravel Query Builder works with it.
SELECT users.name, posts.title
FROM users
RIGHT JOIN posts ON users.id = posts.user_id;
$data = DB::table('users')
->rightJoin('posts', 'users.id', '=', 'posts.user_id')
->select('users.name', 'posts.title')
->get();
| name | title |
|---|---|
| Rahul | Laravel Tips |
| Rahul | PHP Basics |
| Amit | JavaScript |
| NULL | Python |
✅ Python post is included even though the user does not exist
FULL JOIN returns all records from both tables, whether a match exists or not.
⚠️ MySQL does not support FULL JOIN directly, but we can simulate it in Laravel.
$left = DB::table('users')
->leftJoin('posts', 'users.id', '=', 'posts.user_id')
->select('users.name', 'posts.title');
$full = DB::table('users')
->rightJoin('posts', 'users.id', '=', 'posts.user_id')
->select('users.name', 'posts.title')
->union($left)
->get();
| name | title |
|---|---|
| Rahul | Laravel Tips |
| Rahul | PHP Basics |
| Amit | JavaScript |
| Neha | NULL |
| NULL | Python |
✅ Shows all users and all posts
| Join Type | Left Table | Right Table | Only Matching |
|---|---|---|---|
| INNER | ❌ | ❌ | ✅ |
| LEFT | ✅ | ❌ | ❌ |
| RIGHT | ❌ | ✅ | ❌ |
| FULL | ✅ | ✅ | ❌ |
A join in Laravel combines rows from multiple tables based on a related column using Query Builder or Eloquent.
INNER JOIN returns only matching rows, while LEFT JOIN returns all rows from the left table.
Laravel does not support FULL JOIN directly in MySQL, but it can be achieved using UNION.
INNER JOIN is usually the fastest because it returns fewer records.
Understanding Laravel joins is essential for building efficient and scalable applications.
Once you know when to use INNER, LEFT, RIGHT, and FULL JOIN, writing complex database queries becomes simple and predictable.
If you’re serious about backend development in Laravel, mastering joins is non-negotiable.
I'm a dedicated full-stack developer with expertise in building and managing dynamic web applications across both frontend and backend.