0

I have the following interrogation that I want to translate into Laravel's Query Builder:

SELECT t.name, t.description, u.first_name as assignee_fname, u.last_name as assignee_lname, 
us.first_name as reporter_fname, us.last_name as reporter_lname
FROM `tasks` AS t
LEFT JOIN `users` AS u 
ON (t.asignee_id = u.id)
LEFT JOIN `users` AS us
ON (t.reporter_id = us.id);

Do you have any idea how can I do that?

Thank you

1 Answer 1

0
DB::table('tasks')->select('tasks.name', 'users.first_name AS assignee_fname', ...) //and the rest of your column
->leftJoin('users', 'taks.asignee_id', '=', 'users.id')
->leftJoin('users', 'tasks.reporter_id', '=', 'users.id')
1
  • Thank you for the solution. Can I use aliases for the user table as I used in the question? It is important due to the fact that I have to get information for two different persons from the same table.
    – api
    Mar 12, 2014 at 10:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.