Search code examples
google-sheetsgoogle-sheets-query

Google Sheets - query contains array


I have a range with a name column.

I also have a list of names chosen be presented.

I want to run a query which will select data from this range only if it names is inside this list:

Select C Where A "is in the selected array of names"

What would be the right way of doing that?


Solution

  • Suppose the array of names is D2:D10; then you could use the query string

    "select C where A = '" & join("' or A = '", D2:D10) & "'"
    

    This creates a long query string A = 'name' or A= 'another name'...

    If the range of names is variable (e.g., you want all names listed in D2:D), replace D2:D10 with filter(D2:D, len(D2:D)).