i have sql query next join order (two join
's nested in left join
):
select * mytable left join table1 join table2 on table2.id = table1.document_id join table3 on table3.content_id = table2.id on table1.link_id = mytable.link_id
how write query laravel query builder?
my way:
$query = mytable::select('*') ->leftjoin(db::raw('table1 join table2 on table2.id = table1.document_id join table3 on table3.content_id = table2.id '), 'table1.link_id', '=', 'mytable.link_id');
it works, way without db::raw()? maybe $join->nest()
?
the joins aren't nested being used limit number of viable records.
$query = mytable::select('*') ->leftjoin('table1', 'table1.link_id', '=', 'mytable.link_id') ->join('table2', 'table2.id', '=', 'table1.document_id') ->join('table3 ', 'table3.content_id', '=', 'table2.id');
Comments
Post a Comment