Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql 如何在控制器中使用join和WHERNOTIN在Laravel5中构建SQL查询?_Mysql_Laravel - Fatal编程技术网

Mysql 如何在控制器中使用join和WHERNOTIN在Laravel5中构建SQL查询?

Mysql 如何在控制器中使用join和WHERNOTIN在Laravel5中构建SQL查询?,mysql,laravel,Mysql,Laravel,我需要在Laravel Controller中构建以下查询。 查询: 我这样做: $cond = DB::table('table2') ->whereNotIn('id', function($query){ $query->select(DB::raw('table2.id')) ->from('table2 inner join table1 on table2.id = table1.id'); })->get(); 请帮帮我 提前谢谢@br

我需要在Laravel Controller中构建以下查询。 查询:

我这样做:

$cond = DB::table('table2')
->whereNotIn('id', function($query){
     $query->select(DB::raw('table2.id'))
     ->from('table2 inner join table1 on table2.id = table1.id');
})->get();
请帮帮我


提前谢谢

@brnani很高兴能帮忙!若有帮助,您可以接受其他读者的答案:)
$cond = DB::table('table2')->whereNotIn('id', function($sq) { 
    $sq->select('table2.id')
       ->from('table2')
       ->join('table1', 'table2.id', '=', 'table1.id'); 
})->get();
$cond = DB::table('table2')->whereNotIn('id', function($sq) { 
    $sq->select('table2.id')
       ->from('table2')
       ->join('table1', 'table2.id', '=', 'table1.id'); 
})->get();