Laravel 4查询构建器加入DB raw

时间:2015-12-04 08:57:32

标签: php mysql laravel-4 laravel-query-builder

我正在使用laravel 4并拥有像这样的SQL查询

select a.*, v.* from (select * from application order by id desc)a join vacancy v on a.vacancy_id = v.id group by a.email

我的问题是如何在查询构建器中编写

1 个答案:

答案 0 :(得分:0)

您可以尝试这样的事情。 (另)

$subQuery = DB::table('application')->orderBy('id', 'desc');

$result = DB::table(\DB::raw("({$subQuery->toSql()}) as a"))
    ->mergeBindings($subQuery)
    ->selectRaw("a.*, v.*")
    ->join('vacancy as v', 'a.vancancy_id', 'v.id')
    ->groupBy('a.email')
    ->get();