Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

Google Sheets QUERY Where Like: How to Filter Text

· 6 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

The Google Sheets QUERY function does not have a LIKE operator. To filter text that contains, starts with, or ends with a string, use a WHERE clause with MATCHES or CONTAINS instead. For example, =QUERY(A1:C, "SELECT A, B WHERE B CONTAINS 'apple'") returns rows where column B includes the word apple. This guide shows the exact syntax, how to combine conditions, and how to avoid the common errors that make QUERY return #VALUE! or no results.

What You'll Need

  • A Google account and access to Google Sheets (desktop browser recommended; the mobile app has limited formula editing).
  • A spreadsheet with data in a clear range, ideally with a header row.
  • Basic familiarity with the QUERY function syntax: QUERY(data, query, [headers]).

Step-by-Step

  1. Set up your data range. Put your data in columns A through C (or more) with a header row. For example, A1: Product, B1: Category, C1: Price. Select the range you want to query, such as A1:C100.
  2. Write a basic QUERY formula. In an empty cell, type =QUERY(A1:C100, "SELECT A, B, C"). This returns all rows. Press Enter. If you see a #VALUE! error, check that your range includes the header row and that the query string is in double quotes.
  3. Add a WHERE clause with CONTAINS. To filter rows where column B contains the word "fruit", use: =QUERY(A1:C100, "SELECT A, B, C WHERE B CONTAINS 'fruit'"). CONTAINS is case-insensitive and matches the substring anywhere in the cell. Note the single quotes around the text value.
  4. Use MATCHES for pattern matching. MATCHES uses regular expressions. To find values that start with "apple", use: =QUERY(A1:C100, "SELECT A, B, C WHERE B MATCHES '^apple'"). To find values that end with "berry", use MATCHES 'berry$'. To find values that contain "apple" anywhere, use MATCHES '.*apple.*'. The .* means any characters before or after.
  5. Combine multiple conditions. Use AND or OR inside the WHERE clause. For example, to find rows where column B contains "fruit" and column C is greater than 10: =QUERY(A1:C100, "SELECT A, B, C WHERE B CONTAINS 'fruit' AND C > 10"). To find rows where B contains "fruit" or B contains "vegetable": =QUERY(A1:C100, "SELECT A, B, C WHERE B CONTAINS 'fruit' OR B CONTAINS 'vegetable'").
  6. Reference a cell for the search term. Instead of hardcoding the text, put the search term in a cell, say E1, and use: =QUERY(A1:C100, "SELECT A, B, C WHERE B CONTAINS '"&E1&"'"). This lets you change the filter without editing the formula. Be careful with the quotes: the text must be enclosed in single quotes inside the query string, and the cell reference is concatenated with &.
  7. Handle case sensitivity. CONTAINS and MATCHES are case-insensitive by default in Google Sheets QUERY. If you need case-sensitive matching, you cannot do it directly with QUERY; use FILTER with REGEXMATCH instead, or add a helper column that converts text to a consistent case.
  8. Test and adjust. After entering the formula, check the output. If you get a #VALUE! error, the most common cause is mismatched quotes or a missing single quote around a text literal. If you get no results, verify that the column letter in the query matches the column in your range (e.g., if your range starts at column B, then column B in the query refers to the first column of the range).

Common Mistakes

  • Using LIKE instead of CONTAINS or MATCHES. Google Sheets QUERY does not support the SQL LIKE operator. Use CONTAINS for simple substring matching or MATCHES for regular expressions.
  • Forgetting single quotes around text values. In the query string, text literals must be in single quotes, e.g., 'apple'. Double quotes are used to enclose the entire query string.
  • Mismatched column letters. The column letters in the query refer to the columns in the specified data range, not the sheet columns. If your range is B1:D100, then column B in the query is the first column of the range (which is actually column B in the sheet), column C is the second, and so on. This is a common source of confusion.
  • Including headers incorrectly. The third argument of QUERY specifies the number of header rows. If your data has one header row, use 1. If you omit it, QUERY may treat the first row as data. For example: =QUERY(A1:C100, "SELECT A, B WHERE B CONTAINS 'fruit'", 1).
  • Using cell references without concatenation. If you want to use a cell value in the query, you must concatenate it with & and include the single quotes around it, as shown in step 6.
  • Expecting wildcards like * or %. QUERY does not use SQL wildcards. Use regular expressions with MATCHES for pattern matching.

Tips

  • Use CONTAINS for simple "contains" searches; it is easier to read and less error-prone than MATCHES.
  • Use MATCHES when you need patterns like "starts with", "ends with", or more complex conditions. Remember that MATCHES uses RE2 regular expressions, so some advanced features may not be available.
  • To make your query dynamic, put the search term in a cell and reference it. This is useful for dashboards or interactive reports.
  • If you need case-sensitive matching, consider using the FILTER function with REGEXMATCH and the (?i) flag to control case sensitivity, or use a helper column with LOWER or UPPER.
  • Always test your query on a small range first to ensure it returns the expected results before applying it to large datasets.
  • Use the LABEL clause to rename columns in the output, e.g., LABEL A 'Product Name'.

Troubleshooting

  • #VALUE! error: Check that the query string is enclosed in double quotes and that any text literals inside are in single quotes. Also ensure the range is valid and includes the header row if you specify headers.
  • No results returned: Verify that the column letter in the query corresponds to the correct column in your range. Also check that the search term is spelled correctly and that the data actually contains it. Remember that CONTAINS is case-insensitive, so case should not be an issue.
  • #N/A error: This often means the query is valid but no rows match. Double-check your conditions.
  • Unexpected columns: If the output includes columns you did not select, ensure you are using SELECT with the correct column letters. If you omit SELECT, QUERY returns all columns.
  • Formula not updating: If you change the data but the query result does not update, check that the formula is not inside a protected range or that calculation is set to automatic. Go to File > Settings > Calculation and ensure it is set to "On change" or "On change and every minute".
  • Quotes causing errors: If your search term contains a single quote (apostrophe), you need to escape it by doubling it, e.g., 'O''Brien'. Alternatively, use MATCHES with a regular expression that handles the quote.

Frequently Asked Questions

Can I use LIKE in Google Sheets QUERY?

No, Google Sheets QUERY does not support the SQL LIKE operator. Use CONTAINS for substring matching or MATCHES for regular expression matching.

How do I filter text that starts with a specific string?

Use MATCHES with a caret: WHERE B MATCHES '^string'. For example, WHERE B MATCHES '^apple' finds values starting with "apple".

How do I filter text that ends with a specific string?

Use MATCHES with a dollar sign: WHERE B MATCHES 'string$'. For example, WHERE B MATCHES 'berry$' finds values ending with "berry".

Is CONTAINS case-sensitive?

No, CONTAINS is case-insensitive in Google Sheets QUERY. If you need case-sensitive matching, use FILTER with REGEXMATCH and the appropriate flags, or create a helper column.

How do I use a cell reference in a QUERY WHERE clause?

Concatenate the cell reference with the query string using & and enclose the cell value in single quotes. For example: "SELECT A, B WHERE B CONTAINS '"&E1&"'".

Why does my QUERY return #VALUE!?

Common causes include mismatched quotes, missing single quotes around text literals, or an invalid range. Check that the query string is in double quotes and that text values are in single quotes.