I did not find any example of yii2 query builder yii\db\Query using in operator with where clause. for the time being I am using it this way
$result = (new \yii\db\Query)
->select('*')
->from('customer c')
->where('c.status in (' . implode(',', [0,1]) . ')')->all();
But there must be a better way of doing this. Thanks in advance
$result = (new \yii\db\Query)
->select('*')
->from('customer c')
->where(['c.status' => [0, 1]])->all();
In the yii\db\QueryInterface::where() API:
The
$conditionspecified as an array can be in one of the following two formats:
- hash format:
['column1' => value1, 'column2' => value2, ...]- operator format:
[operator, operand1, operand2, ...]... In case when a value is an array, an
INexpression will be generated.
['id' => [1, 2, 3], 'status' => 2]generates(id IN (1, 2, 3)) AND (status = 2).
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