Need help using the QUERY "WHERE" clause with multiple conditions

206 views
Skip to first unread message

Glenn Barker

unread,
Jul 3, 2023, 8:41:57 PM7/3/23
to Google Visualization API
Hi, I'm totally new to this and need some advice.

I'm currently using the QUERY function with the WHERE clause to filter an IMPORTRANGE.  The WHERE clause has multiple conditions separated by OR operators. Example of a working query that has 4 conditions using OR operators:

QUERY(IMPORTRANGE("[URL]","equipment!A2:T"),"SELECT Col1, Col3, Col9, Col10 WHERE (Col10 = '"&Filters!F3&"' or Col10 = '"&Filters!F4&"' or Col10 = '"&Filters!F5&"' or Col10 = '"&Filters!F6&"')")  

The OR operators work fine for me in the circumstance that my list of conditions to filter against is short.  However, I want to be able to filter the IMPORTRANGE against a column of values that changes and could be dozens or hundreds of values long... far too big for using a hardcoded string of OR statements.

How can I QUERY the IMPORTRANGE against all the values listed in a column as the conditions? If I use an array as the condition for the query... for example...

 QUERY(IMPORTRANGE("[URL]","equipment!A2:T"),"SELECT Col1, Col3, Col9, Col10 WHERE Col10 = '"&Filters!F3:F100&"' ")    

... it only returns the first condition in the column.  

Greatly appreciate any response on how to solve this problem.

Joe Davies

unread,
Jul 4, 2023, 2:08:25 AM7/4/23
to Google Visualization API
Have you tried using the IN operator which is a standard method for SQL. If non numeric you need to enclose values with single quotes. 
HTH

SELECT column_name(s)
FROM table_name
WHERE column_name IN (value1, value2, ...);

Glenn Barker

unread,
Jul 4, 2023, 4:03:33 AM7/4/23
to Google Visualization API
Thank you. I tried, but no luck.
I know I could use a JOIN function to create the string (value 1, value 2, ... ) from the column of values (numbers in text) that I want to use as the query key, but unfortunately (according to the Google Visualization API Query Language reference), the IN operator is not available for use with the WHERE clause.  Maybe there's a workaround for IN?

Glenn Barker

unread,
Jul 4, 2023, 4:07:34 AM7/4/23
to Google Visualization API
... and I should have mentioned from the start that I'm doing this in Google Sheets.
Reply all
Reply to author
Forward
0 new messages