Google Sheets Query Multiple Criteria: How-To

How-to basics · Updated November 23, 2026

To query multiple criteria in Google Sheets, use the QUERY function with a WHERE clause that combines conditions using the AND or OR operators, for example: =QUERY(A1:C100, "SELECT * WHERE B = 'Yes' AND C > 10"). This returns only the rows where both conditions are true; for rows meeting any of several conditions, use OR instead.

What the QUERY Function Does

QUERY is a built-in Google Sheets function that runs a structured query language (SQL-like) statement against a range of data. It is one of the most powerful functions in Sheets because it can filter, sort, aggregate, and pivot data in a single formula. The basic syntax is =QUERY(data, query, [headers]), where data is the range to search, query is a text string containing the SQL-like instructions, and the optional headers argument tells Sheets how many header rows are in the data.

When you need to filter based on more than one condition, you put those conditions inside the WHERE clause. The WHERE clause supports logical operators AND, OR, and NOT, as well as comparison operators like =, <>, >, <, >=, <=, and the text matching operators CONTAINS, STARTS WITH, ENDS WITH, LIKE, and MATCHES. You can also use the IN operator to test against a list of values.

Using AND for All Conditions Must Be True

If you want rows that satisfy every condition simultaneously, connect the conditions with AND. For example, suppose you have a list of sales orders in A1:E100 with columns: Order ID (A), Region (B), Salesperson (C), Amount (D), and Date (E). To get all orders from the West region with an amount greater than $500, you would write:

=QUERY(A1:E100, "SELECT * WHERE B = 'West' AND D > 500")

This returns every column for rows where column B exactly equals “West” and column D is greater than 500. Note that text values in the query string must be enclosed in single quotes. If you want to reference a cell for the criteria, you can concatenate the cell value into the query string, for example: =QUERY(A1:E100, "SELECT * WHERE B = '"&G1&"' AND D > "&H1) where G1 contains the region and H1 contains the threshold.

Using OR for Any Condition Can Be True

When you want rows that meet at least one of several conditions, use OR. For instance, to get orders from either the West or the East region, you would write:

=QUERY(A1:E100, "SELECT * WHERE B = 'West' OR B = 'East'")

You can mix AND and OR, but you must use parentheses to group conditions correctly, just like in math. For example, to get orders from West with amount over 500, or orders from East with amount over 1000, you would write:

=QUERY(A1:E100, "SELECT * WHERE (B = 'West' AND D > 500) OR (B = 'East' AND D > 1000)")

Without the parentheses, the logic changes because AND has higher precedence than OR. Always use parentheses when mixing to avoid unexpected results.

Using IN, CONTAINS, and Other Operators

Beyond simple equals, QUERY supports several other operators that are useful for multiple criteria:

  • IN – checks if a value is in a list: WHERE B IN ('West', 'East', 'North') is the same as three OR conditions.
  • CONTAINS – checks if a text cell contains a substring (case-insensitive): WHERE C CONTAINS 'John' matches “John”, “Johnny”, “Mary Johnson”.
  • STARTS WITH and ENDS WITH – match text at the beginning or end: WHERE B STARTS WITH 'W'.
  • LIKE – uses % as a wildcard: WHERE B LIKE 'W%' is similar to STARTS WITH.
  • MATCHES – uses regular expressions for powerful pattern matching.
  • IS NULL / IS NOT NULL – filter for empty or non-empty cells.

For example, to find orders where the salesperson’s name contains “Lee” and the amount is not blank, you could use: =QUERY(A1:E100, "SELECT * WHERE C CONTAINS 'Lee' AND D IS NOT NULL").

Referencing Cell Values in the Query

Hardcoding criteria in the query string works, but often you want the criteria to change based on input cells. To do that, you build the query string dynamically using concatenation. For example, with a region in cell G1 and a minimum amount in cell H1, the formula would be:

=QUERY(A1:E100, "SELECT * WHERE B = '"&G1&"' AND D > "&H1)

Be careful with text values: you must wrap the cell reference in single quotes inside the string. For numbers, no quotes are needed. If the cell might contain a date, you need to format it as a string that Sheets recognizes, for example using the TEXT function: =QUERY(A1:E100, "SELECT * WHERE E > DATE '"&TEXT(I1, "yyyy-mm-dd")&"'").

Common Errors and How to Fix Them

Several errors are common when using multiple criteria in QUERY:

  • #VALUE! error – often caused by mismatched data types. For example, if column D contains text numbers, comparing with a numeric value may fail. Ensure your data is consistently formatted.
  • Formula parse error – usually a syntax issue in the query string, like missing quotes or parentheses. Double-check that you have single quotes around text literals and that parentheses are balanced.
  • No data returned – if your criteria are too restrictive or the column references are wrong, you get an empty result. Verify that column letters match your range and that text matches exactly (or use CONTAINS for partial matches).
  • #REF! error – the range reference is invalid, often because the range is not in the same sheet or the sheet name contains spaces. Use single quotes around sheet names like 'Sheet 1'!A1:C100.

Another common mistake is using double quotes inside the query string. In Sheets, the query string itself is in double quotes, so any internal quotes must be single quotes. If you need to include a single quote inside the text (like an apostrophe), you can double it: "WHERE B = 'O''Brien'".

Alternatives to QUERY for Multiple Criteria

While QUERY is powerful, sometimes other functions are simpler or more familiar:

  • FILTER – returns an array of rows that meet conditions. For example: =FILTER(A1:E100, B1:B100="West", D1:D100>500). FILTER uses AND logic between conditions; to do OR, you can use addition: =FILTER(A1:E100, (B1:B100="West")+(B1:B100="East")). FILTER is often easier to read and doesn’t require string syntax.
  • SUMIFS / COUNTIFS / AVERAGEIFS – when you only need a summary (sum, count, average) based on multiple criteria, these functions are more direct. For example, =SUMIFS(D1:D100, B1:B100, "West", D1:D100, ">500") sums amounts for West over 500.
  • QUERY with pivot – if you need to aggregate and group by multiple criteria, QUERY’s pivot clause is handy: =QUERY(A1:E100, "SELECT B, SUM(D) WHERE C CONTAINS 'Lee' GROUP BY B PIVOT C").

Choose QUERY when you need complex filtering, sorting, and aggregation in one formula. Choose FILTER when you want a simple, readable filter that returns the actual rows. Choose SUMIFS/COUNTIFS for quick summary statistics.

Frequently Asked Questions

How do I use QUERY with multiple criteria from different columns?

Simply include conditions on different columns in the WHERE clause, separated by AND or OR. For example, =QUERY(A1:C100, "SELECT * WHERE A = 'Yes' AND B > 5") filters on column A and column B. There is no limit to the number of conditions, but be mindful of performance on very large datasets.

Can I use QUERY with OR and AND together?

Yes, you can mix them, but you must use parentheses to group conditions so the logic is correct. For example, =QUERY(A1:C100, "SELECT * WHERE (A = 'X' AND B > 10) OR (A = 'Y' AND B < 5)"). Without parentheses, AND is evaluated first, which may not be what you intend.

Why is my QUERY returning #VALUE! when I compare text?

This usually happens when the column contains numbers but you are comparing with text, or vice versa. Check that the data type in the column matches the literal in your query. If the column contains numbers stored as text, you can use the VALUE function in a helper column or use a comparison like CONTAINS instead.

How do I reference a cell for the criteria in QUERY?

Use concatenation with the ampersand (&) to build the query string. For text criteria, wrap the cell reference in single quotes: "WHERE B = '"&G1&"'". For numbers, just concatenate: "WHERE D > "&H1. For dates, use the TEXT function to format the date as a string.

Is QUERY case-sensitive?

By default, text comparisons in QUERY are case-insensitive for the equals operator. However, the CONTAINS, STARTS WITH, and ENDS WITH operators are also case-insensitive. If you need case-sensitive matching, use the MATCHES operator with a regular expression, or use FIND in a helper column.

What is the difference between QUERY and FILTER for multiple criteria?

QUERY uses a text-based SQL-like syntax and can also sort, aggregate, and pivot. FILTER uses array conditions and is simpler for just filtering rows. FILTER uses AND logic between conditions; for OR logic, you add conditions with a plus sign. QUERY is more flexible for complex logic but has a steeper learning curve.

Related

Try it: the Date Difference Calculator: days, months, years and weekdays between two dates, with the DATEDIF formulas.

More in How-to basics

Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources

Spotted an error in this guide? Let us know.