PHP Laravel 6 Inner Join Query Example

Admin   Laravel   430  2021-03-17 14:40:08

hi guys,

In this tutorial, I will learn you to use inner join query builder in laravel 6 project. i will write simple inner join query using laravel 6 query builder. we will use db(), join() to write inner join query in laravel 6.

The first argument passed to the join method is the name of the table you need to join to, while the remaining arguments specify the column constraints for the join. You can even join to multiple tables in a single query.

In this example, i will create two tables users and companies. i will display to company id to users table.

inner join query builder


public function usersGet()


$users = DB::table('users')

->join('companies', '', '=', 'users.company_id')

->select('users.*', 'companies.company_name')


echo '<pre>';




Users Table

you have to create the Users table.

companies Table

you have to create the companies table.




[0] => stdClass Object


[id] => 1

[company_id] => 1

[name] => keval

[email] => [email protected]

[email_verified_at] =>

[password] => 123456

[remember_token] =>

[created_at] =>

[updated_at] =>

[company_name] => yahoo


[1] => stdClass Object


[id] => 2

[company_id] => 2

[name] => mehul

[email] => [email protected]

[email_verified_at] =>

[password] =>

[remember_token] =>

[created_at] =>

[updated_at] =>

[company_name] => google



It will help you....