Active query where 'IN' in the opposite way


Normally, when we use ‘IN’ condition in MySQL, we will use field IN datas. However, sometimes we will have same data ‘IN’ fields (For ex. we need to work in an old database with bad design). Fortunately, MySQL still allow we to do it.

Case 1 (field in datas)

SELECT * FROM `track` WHERE `artist` IN ('a', 'b', 'c')

Case 2 (data in fields)

SELECT * FROM `track` WHERE 'abc' IN (`artist1`, `artist2`, `artist3`)

I know I can transfer case 2 to WHERE with OR. But I think ‘IN’ will more effectively.

Does Yii2 active query support to do case 2? If yes, how can I do it?


I think you can solve only handling ‘or’ condition field by field

Hi Fabrizio Caldarelli,

Thanks for your support. Finally, I had to use ‘or’ condition.

So sorry for my late response!