欢迎各位兄弟 发布技术文章

这里的技术是共享的

You are here

Laravel Query Builder WHERE NOT IN

 

I have the following sql query

SELECT * FROM exams WHERE exams.id NOT IN (SELECT examId FROM testresults)

how can I convert it into Laravel query builder format?

Thanks.


I have the following sql query

SELECT * FROM exams WHERE exams.id NOT IN (SELECT examId FROM testresults)

how can I convert it into Laravel query builder format?

Thanks.

I have the following sql query

SELECT * FROM exams WHERE exams.id NOT IN (SELECT examId FROM testresults)

how can I convert it into Laravel query builder format?

Thanks.


正确答案 

You can use whereNotIn with a closure:

$result = DB::table('exams')->whereNotIn('id', function($q){
    $q->select('examId')->from('testresults');
})->get();
shareimprove this answer

来自 https://stackoverflow.com/questions/28361461/laravel-query-builder-where-not-in
普通分类: