IN/NOT IN
和EXISTS/NOT EXISTS
之类的查询可以直接使用闭包作为子查询
Db::table('think_user')
->where('id','IN',function($query){
$query->table('think_profile')->where('status',1)->field('id');
})
->select();
生成的SQL语句是
SELECT * FROM `think_user` WHERE `id` IN ( SELECT `id` FROM `think_profile` WHERE `status` = 1 )
Db::table('think_user')
->where(function($query){
$query->table('think_profile')->where('status',1);
},'exists')
->find();
生成的SQL语句为
SELECT * FROM `think_user` WHERE EXISTS ( SELECT * FROM `think_profile` WHERE `status` = 1 )