2016-06-01 71 views
4

我在用这个查询没有条件:Yii2 NOT IN不工作

$usertypes=Usertype::find()->where(['not in ','user_type_id',['2,3,4']])->all(); 

错误:

Database Exception – yii\db\Exception 

未定义抵消:1 无法准备SQL:SELECT * FROM usertype WHERE user_type_id NOT IN:qp0

也尝试过阵列格式为['2','3','4']但不起作用?问题是什么?

+0

删除sp ace'from'where(['in',' –

+0

它看起来像你已经找到了解决方案,但值得注意的是,你可以否定这样的条件:' - > where(['not',['user_type_id' => ['2','3','4']]])'。 – spencer4of6

回答

0

也许从'not in '删除空格字符? $usertypes=Usertype::find()->where(['not in', 'user_type_id', ['2,3,4']])->all();

+0

谢谢!固定:) – Jackhad

0

尝试使用 - > andFilterWhere而不是在那里 - >其中

试试这个:

$usertypes=Usertype::find() ->andFilterWhere(['NOT IN','user_type_id',[2,3,4]]) ->all();

+0

是的。您说得对!它的工作现在 – Jackhad

+0

没问题!不客气 –