We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Querybuilder: Combining IN, AND and OR

Hi,

I am having problems making the querybuilder make the querry that I need. I can use the inWhere(), andWhere() and orWhere() alone or combining any two. But when I need to use all three in the query I run into a problem.

I need to form a query that does :

(colA IN array) AND ((colB = '0') OR  (colC IN array))


145.0k
Accepted
answer
where("colA in ({array:array}) AND (colB= '0' OR colC IN ({anotherArray:array}))", ['array'=>[1, 2, 3], 'anotherArray' => [1, 2, 3]]);


1.6k

Thank you so much!

edited Jul '16

You can maybe try it like this if you like methods so much more:

->where("(colB = '0'")
->orWhere('colC IN ({anotherArray:array}))')
->andWhere('colA IN ({array:array})'

But can't guarantee it will work. Perhaps even adding inWhere as first could make a job, don't know, im using where always beacause i have seperated helpers for conditions/bind mostly.