1
votes

When I use the Query function like this using a number, it returns the correct results:

=QUERY(Sheet2!A1:B12,"select B where A matches '1200'", 0)

But, when I try to match a string, the result is always an empty output:

=QUERY(Sheet2!A1:B12,"select B where A matches 'qwerty'", 0)

This seems ultra-simple, but I can't seem to find an answer anywhere.. What exactly is the correct syntax to match the string? I've included an example of my problem here: sheets_query

3

3 Answers

1
votes

I suggest you format ColumnA of Sheet2 as Plain text.

1
votes

This indeed is simple, instead of matches, you need to use an "=" symbol. So your formula will be =QUERY(Sheet2!A1:B12,"select B where A='qwerty'", 0)

0
votes

for number it would be:

=QUERY(Sheet2!A1:B12, "select B where A = 1200", 0)

for text, it would be:

=QUERY(Sheet2!A1:B12, "select B where A = 'qwerty'", 0)

for number with external reference:

=QUERY(Sheet2!A1:B12, "select B where A ="&1200, 0)

for text with external reference:

=QUERY(Sheet2!A1:B12, "select B where A = '"&"qwerty"&"'", 0)

for mixed data you can either format it as Plain text or:

=ARRAYFORMULA(QUERY(TO_TEXT(Sheet2!A1:B12), "select Col2 where Col1 = 'qwerty'", 0))