Reputation: 103
The code below is not working.
$subQuery = DB::table('table1')->groupBy('col');
$data = DB::table($subQuery, 'sub')->get();
Can you help me with this?
Upvotes: 0
Views: 610
Reputation: 15849
Your code is already functional. The only alternative (to make the same query) is to inline the $subQuery
part.
$subQuery = DB::table('table1')->groupBy('col');
$data = DB::table($subQuery, 'sub')->get();
Is the same as
$data = DB::table(function ($sub) {
$sub->from('table1')
->groupBy('col');
}, 'sub')
->get();
or
$data = DB::table(DB::table('table1')->groupBy('col'), 'sub')->get();
Upvotes: 5