[英]Laravel 5.4 subquery in where condition?
I want to write sub query inside where in condition and in subquery were condition, checking with parent query field. 我想在条件和子查询条件的内部写子查询,用父查询字段检查。
as follows, 如下,
$query = DB::table('users');
$query->whereNotIn('users.id', function($query) use ($request) {
$query->select('award_user.user_id')
->from('award_user')
->where('award_user.user_id', 'users.id')
->where('award_user.award_id', $request->award_id);
});
Query is working fine, but 查询工作正常,但是
->where('award_user.user_id', 'users.id')
This line, users.id is not taking from parent query. 这行,users.id不是从父查询中获取的。 If I enter manually number, then it is working correctly.
如果我手动输入数字,那么它正常工作。
What is wrong with my query.. can you please suggest. 我的查询有什么问题..你可以建议吗?
use whereRaw
rather than where
使用
whereRaw
而不是where
$query = DB::table('users');
$query->whereNotIn('users.id', function($query) use ($request) {
$query->select('award_user.user_id')
->from('award_user')
->whereRaw('award_user.user_id', 'users.id')
->whereRaw('award_user.award_id = '.$request->award_id);
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.