I use this for query not in:
$usertypes=Usertype::find()->where(['not in ','user_type_id',['2,3,4']])->all();
Error:
Database Exception – yii\db\Exception
Undefined offset: 1
Failed to prepare SQL: SELECT * FROM usertype
WHERE user_type_id
NOT IN :qp0
also tried the array format as ['2','3','4'] but not works?What is the issue?
Try This :
$usertypes=Usertype::find()
->where(['not in','user_type_id',[2,3,4]])
->all();
OR :
$usertypes=Usertype::find()
->where(['NOT',['user_type_id'=>[2,3,4]]])
->all();
Refer : http://www.bsourcecode.com/yiiframework2/select-query-model/#In-Condition
Maybe remove space character from 'not in '
?
$usertypes=Usertype::find()->where(['not in', 'user_type_id', ['2,3,4']])->all();
you can use "not
" word or "<>
"
$usertypes=Usertype::find()->where(['not',['user_type_id'=>['2,3,4']]])->all();
or this
$usertypes=Usertype::find()->where(['<>',['user_type_id'=>['2,3,4']]])->all();
Try to use ->andFilterWhere
instead of where ->where
Try this:
$usertypes = Usertype::find()
->andFilterWhere(['NOT IN','user_type_id',[2,3,4]])
->all();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With