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();
with Eloquent :
$result = Exams::whereNotIn('id', function($q){
$q->select('examId')->from('testresults');
})->get();
© 2022 - 2024 — McMap. All rights reserved.