我正在多个表上运行查询,我想将其限制为5个结果,但它会给我以下错误。
$projects = DB::query("select * from project, project_budget,user
where prj_id=pb_prj_id
and prj_usr_id=usr_id
and prj_status = 'open'
and prj_expiry>'".date("Y-m-d H:i:s")."'
order by prj_updated_date desc")->take(5)->get();
SQLSTATE [HY000]:常规错误:1096未使用任何表(SQL:select * limit 5)
答案 0 :(得分:0)
我使用查询构建器解决了这个问题。
$projectExpiry = date("Y-m-d H:i:s");
$projects = DB::table('project')
->join('project_budget', 'project.prj_id', '=', 'project_budget.pb_prj_id')
->join('users', 'project.prj_usr_id', '=', 'users.prj_usr_id')
->where('prj_status', '=' , 'open')
->where('prj_expiry', '<' , $projectExpiry )
->orderBy('prj_updated_date', 'desc')
->take(5)->get();