Google-sheets – Google Sheets queries: using WHERE IN

google sheetsgoogle-sheets-query

My problem

I have a table of ids and terms in Google Sheets. I would like to concatenate a few terms by their ids.

For example, (2,3) should yield Talla de zapato de mujer, Women’s shoe size. I want to take id list from a separate cell.

enter image description here

So, I tried:

=QUERY(A:B, "SELECT A,B WHERE A=2 OR A=3")

enter image description here

The query works fine, but it's hard to manually extract the 2's and 3's this way.

So I tried:

=QUERY(A:B, "SELECT A,B WHERE A IN (2,3)")

Which does not work (VALUE error).

My question

How can I select ids from a table using a GSheets query using a few ids written in a different cell?

Best Answer

The =QUERY() language WHERE clause support regex; so you can "simulate" IN functionality using a regex group - ie:

=QUERY(A:B, "SELECT A,B WHERE A MATCHES '(2|3)'")