Home > Software engineering >  QUERY function with OR condition > Query Table, Select E where C contains Cell1 *OR* Cell2 limit
QUERY function with OR condition > Query Table, Select E where C contains Cell1 *OR* Cell2 limit

Time:03-22

I am attempting to use OR operator in the following Query.

The idea is that the cell will display mileage from a branch. The user can select a branch at either C12 or E12, and the cell will display the mileage from the table. My next move would be to make an if statement but I'm wondering if its possible to make it work like this

=iferror(query(BranchesHrsKms, "Select E where C matches'"&C12&"' or C matches'"&E12&"'limit 1",0),"")`

What the current code does: Basically just runs this part

C matches'"&E12&"'limit 1",0),"")

But only when there is something in C12.

Any guidance appreciated

Update: It can work with If and ISBLANK

=IF(ISBLANK(C16)=FALSE, iferror(query(BranchesHrsKms, 
"Select E where C matches'"&C16&"' limit 1",0),""), 
iferror(query(BranchesHrsKms, "Select E where C matches'"&E16&"' limit 1",0),""))

Copy of sheet to play with: enter image description here

CodePudding user response:

There is a lack of space before limit

=iferror(query(BranchesHrsKms, "Select E where C contains '"&C12&"' or C contains '"&E12&"' limit 1",0),"")
  • Related