Link to home
Start Free TrialLog in
Avatar of tjyoung
tjyoung

asked on

Trouble with retrieving all records from a table using a join

Hi,
I'm sure its simply something obvious but I can't seem to figure it out:

I have a query in Laravel that I'm getting to retrieve all my users.

$users = DB::table('users')
      ->join('dealerships', 'users.dealership_id', '=', 'dealerships.id')
      ->join('roles', 'users.role_id', '=', 'roles.id')
      ->select('users.*','roles.*','dealerships.name')

Currently this returns all the users that are assigned to a dealership (records that have a value for users.dealership_id) . Problem is I need all the users regardless if a dealership has been assigned to them. I could skip the join, but I need the dealership name for those records that have a dealership assigned to them

if there someway to join the tables so I get all users and within my results also the dealership name for those that have one?



 Hope that makes sense. Thanks in advance.
ASKER CERTIFIED SOLUTION
Avatar of Andrew Kalik
Andrew Kalik
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of tjyoung
tjyoung

ASKER

thanks a million!