我需要在Laravel Controller中构建以下Query。 查询:
select * from table2 where id not in (select table2.id from table2 inner join table1 on table2.id = table1.id)
我这样做了:
$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();
请帮助我。
提前致谢
答案 0 :(得分:1)
$cond = DB::table('table2')->whereNotIn('id', function($sq) {
$sq->select('table2.id')
->from('table2')
->join('table1', 'table2.id', '=', 'table1.id');
})->get();