0

I would like to ask how to use Query function where one of the cell contains multiple comma separated values

For example:-

To pull col2 values when Col 1 is B, it would be straightforward.

Col 1 Col 2
A 1
B 2
C 3
D 4
=QUERY(A1:B3,"select B where A = '"&D3&"' ",0)

D3 cell value is B

Similar to how we have IN clause in SQL, I would like to pull data from col 2 when col1 values are B,C,D.

Would it be possible to concatenate the results in one row as well?

1 Answer 1

1

Try this one:

=join(", ", QUERY(A1:B4,"select B where "&CONCATENATE("A = '", join("' or A = '", SPLIT(D4, ",")), "'"),0))

Where D4 = B,C,D

Sample Output:

Sample

Note:

  • The values on column B below are the value of the formula:

CONCATENATE("A = '", join("' or A = '", SPLIT(D4, ",")), "'"),0))

Since there was no in statement in sheets query (not that I have encountered), what I did was split those said values in column D and have them format like the multiple or statements which are equal to a single in statement. This is a workaround and should do what you wish to achieve.

Sign up to request clarification or add additional context in comments.

1 Comment

Excellent stuff!! Thank you so much NaziA. God bless

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.