Google Sheets Query match multiple numbers

248 Views Asked by At

This article explains that SQL IN is not available in Google Query, so it recommends using "matches" separating the parameters with vertical bars, like so: =QUERY($A$1:$B,"SELECT A WHERE B matches 'Apple|Banana'"). Based on this answer, you can even do partial matches like so: where A matches '.*apple.*|.*banana.*'

However, this vertical bar syntax does not seem to work when the source column contains numbers: =QUERY($A$1:$B,"SELECT A WHERE B matches '17|32'").

I've tried (with no luck): 17|32, '17'|'32', ('17|32'), ('17'|'32'). Then I thought perhaps I could first convert column B to text, but that didn't work either: text(B) matches '17', etc.

2

There are 2 best solutions below

0
SAL On

It was the one combination I didn't think of trying - '17|32' (although '(17|32)' works too):

=QUERY($A$1:$B,"SELECT A WHERE B matches '17|32'")

0
z.. On

Try

=QUERY(A1:B,"SELECT A WHERE B matches '.*(17|32).*'")