-1

How can I write update query with where, in and not in condition. I tried this one but it's not working properly. It updates all rows in a table. Not only working for mentioned rows but also all rows.

$postval=('2,4,5,7');
$netchk=TblNetwork::updateAll(['status' => 0],['AND', 
                'status = 1',  ['NOT IN', 'network_id_pk', $postval]
                ]);
rob006
  • 21,383
  • 5
  • 53
  • 74
  • Check out syntax for updateAll at https://stackoverflow.com/questions/32477678/yii2-updateall-with-multi-conditions and https://www.yiiframework.com/doc/api/2.0/yii-db-activerecord#updateAll()-detail. – lubosdz Feb 22 '19 at 07:38
  • Your update is condition is not clear .. try add the equivalent flat sql query so we can try to understand your goal – ScaisEdge Feb 22 '19 at 08:13

1 Answers1

0

You should use array of IDs for NOT IN condition (in you're example you're using string with list of IDs):

$postval = [2, 4, 5, 7];
$netchk = TblNetwork::updateAll(['status' => 0], [
        'AND', 
        'status = 1',  
        ['NOT IN', 'network_id_pk', $postval]
    ]);
rob006
  • 21,383
  • 5
  • 53
  • 74