Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

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))


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


771

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.