subquery in laravel

Solutions on MaxInterview for subquery in laravel by the best coders in the world

showing results for - "subquery in laravel"
Anton
26 Jan 2017
1In addition to @delmadord's answer and your comments:
2
3Currently there is no method to create subquery in FROM clause, so you need to manually use raw statement, then, if necessary, you will merge all the bindings:
4
5$sub = Abc::where(..)->groupBy(..); // Eloquent Builder instance
6
7$count = DB::table( DB::raw("({$sub->toSql()}) as sub") )
8    ->mergeBindings($sub->getQuery()) // you need to get underlying Query Builder
9    ->count();
10Mind that you need to merge bindings in correct order. If you have other bound clauses, you must put them after mergeBindings:
11
12$count = DB::table( DB::raw("({$sub->toSql()}) as sub") )
13
14    // ->where(..) wrong
15
16    ->mergeBindings($sub->getQuery()) // you need to get underlying Query Builder
17
18    // ->where(..) correct
19
20    ->count();
Iliana
18 Mar 2018
11AVG(SUM(amount))
queries leading to this page
subquery in eloquent laravelselect query laravel with sub tablelaravel select table on subquerylaravel wherein subqueryhow to make subquery in select statement laravelsubquery in select method laravellaravel query builder subqueryeloquent subquery selectsubquery in select statement laravelsubquey in laraveleloquent select subquerysubquery select laravel query builderlaravel where subqueryeloquent subquery wheresubqueries laravelsubquery in laravel in selectselect query conatins subquery in laravellaravel select inside subquerysubqueries in laravellaravel select subquerylaravel sql subquerylaravel subquery in whereselect from subquery laravelsub query in laravallaravel eloquent select subqueryscript select sub categories laraveluse subquery with select in laravellaravel select from subsubquery in where clause laravelsubquery in db select method laravellaravel subquery withsubquery in select laravellaravel sub query in slectlaravel subquerylaravel with subquerylaravel subquery fromwith subquery laravellaravel sub queryselect subquery in laravel eloquentsubquery select laravelsub query in laravelsub select query laravellaravel subqueriessubselect laravellaravel eloquent from subquerylaravel subquery selectlaravel subquery in selectlaravel subquery uselaravel from subquery selectlaravel eloquent subquerysubquery in laraveleloquent laravel subquerylaravel subquery wherehow to write subquery in laravel selectlaravel subselectsub query laravellaravel eloquent subquery selectwrite sub query in laravel selectsubquery in where laravelhow to subquery in laravellaravel from subquerylaravel select from subquerysubquery in laravel eloquentsubquery in sql laravelhow to use sub queries in laravellaravel create subqueryquery from sub laravelwhere query laravel subquerysub query in laravel eloquentsubquery laravelsub queries laravellaravel select subquery query builderhow to write subquery in subquery in laravel 8 eloquentelequoent subquery laravellaravel query where in subquerysubquery laravel elquentsubquery laravel eloquenteloquent subquerywhere subquery laravelsubquery in select statement eloquent laravellaravel subquery in fromlaravel subquery examplelaravel select result from subquerylaravel sub selectsubquery in laravel