google-sheetsgoogle-query-languageand-operator

Joining more than two WHERE statements in Query Language


So I am trying to use a simple QUERY function in Google Sheets where I want to select based on TWO parameters. Simple logic, and documentation says use the AND operator. The problem is I am searching for text via Cell Reference.

So here is my function

=QUERY(A1:D6,"select A where C='" &K1&'"" & "and D='" &K2"'")

Unfortunately it throws up an ERROR. I understand that Cell References that are text based need to be in single quotes (which themselves need to be in double quotes), but I am unable to join two WHERE statements.

What is the right syntax for this?


Solution

  • Very close indeed, please try:

    =query(A1:D6,"select A where C='"&K1&"' and D='"&K2&"' ")