How to Use LIKE String Operator in Google Sheets Query

The LIKE string operator in Google Sheets Query is for complex string comparisons.

You can use it with the WHERE keyword for text searches.

The LIKE enables using two wildcards in Google Sheets QUERY function: % (percentage) and _ (underscore).

These two wildcards are similar to the asterisk and question mark used in many other native Google Sheets functions.

The WHERE clause in Query helps filter rows based on given conditions (criteria).

The comparison operators play a vital part in it.

There are complex as well as simple comparison operators.

To learn about the other complex comparison operators in the Query function, please check the section “Additional Resources” at the end of this post.

Let’s see how to use the LIKE (similar to SQL LIKE) complex string comparison operator in Google Sheets Query.

Using LIKE String Comparison Operator in Google Sheets Query

Important Notes:

  1. The LIKE is a case-sensitive string comparison operator for use in the Google Sheets Query function. To bring case insensitivity, use the scalar functions Lower or Upper with the criterion.
  2. As I have already mentioned, it supports two wildcards: % (percentage) and _ (underscore).

    Related: How to Use Wildcard Characters in Google Sheets Functions.

    Sample Data: We will use this data for a couple of examples below, but not with all.

    LIKE String Operator in Google Sheets - Example

    The Use of % (Percentage) Wildcard in Query (Alternative to Asterisk)

    You can use the percentage wildcard in the LIKE operator to match zero or more characters of any kind.

    Formula 1:

    =query(A2:A,"Select A where A like '%'")

    It’s just like using the wildcard character *. It returns all the country names in column A as it’s.

    Formula 2:

    =query(A2:A,"Select A where A like 'A%'")

    Result:

    Australia
    Austria
    Auckland

    What does it mean? It means the percentage wildcard in LIKE returns all the strings starting with the letter “A”.

    Formula 3:

    =query(A2:A,"Select A where A like '%land'")

    Result:

    Oakland
    Auckland

    Formula 4:

    =query(A2:A,"Select A where A like 'Sl%ia'")

    Result:

    Slovakia
    Slovenia

    Hope the above formulas answer how to use the % wildcard in the LIKE string comparison operator in Google Sheets Query.

    The Use of _ (Underscore) Wildcard in Query (Alternative to Question Mark)

    Use the underscore wildcard in Query to match any single character. It’s like the use of the wildcard “?”.

    Note: I am not following the above sample data here.

    Here is one example formula.

    =query(A2:A,"Select A where A like 'Am_'")

    This would return the names like Ami, Amy, etc.

    =query(A2:A,"Select A where A like 'A__'")

    In this formula, I’ve used a double underscore. It can return the names like Ann, Ash, etc.

    Hope you have learned now how to use the LIKE string comparison operator in Google Sheets Query.

    Finally, if you want to make the above formulas case-insensitive, please follow the below logic.

    =query(A2:A,"Select A where lower(A) like 'a__'")

    See how I’ve used thelower() scalar function in the formula.

    We usually specify a criterion in a cell and refer to that in the formula. You can follow that within the LIKE also.

    Here is a detailed tutorial on how to use LIKE with a criterion specified in a cell – How to Use Cell Reference in Google Sheets Query.

    Not LIKE String Operator Use in Google Sheets Query

    In all the above examples, we can negate the condition by placing NOT before the column identifier.

    Here is one example of how to perform a Not LIKE string comparison operation in Google Sheets Query.

    Not with Percentage Wildcard:

    Assume there are country names in column A.

    =query(A2:A,"Select A where not(A) like 'A%'")

    The above formula will return the country names that don’t start with the letter A.

    Not with Underscore Wildcard:

    Assume there are a few names in column A.

    =query(A2:A,"Select A where not(A) like 'Am_'")

    This formula will return any names that start with “Am” and have 3+ characters.

    It won’t return the name “Ami”, But would return “Ami Santo”.

    Additional Resources

    1. Matches Regular Expression Match in Google Sheets Query.
    2. CONTAINS Substring Match in Google Sheets Query for Partial Match.
    3. Starts with and Not Starts with Prefix Match in Query.
    4. Ends with and Not Ends with Suffix Match in Query.
    Prashanth KV
    Prashanth KV
    Your Trusted Google Sheets and Excel Guide Prashanth KV brings a wealth of experience in Google Sheets and Excel, cultivated through years of work with multinational corporations in Mumbai and Dubai. As a recognized Google Product Expert in Docs Editors, Prashanth shares his expertise through insightful blogging since 2012. Explore his blog for practical tips and guidance on maximizing your spreadsheet skills.

    Calculate Weighted Average in Pivot Table in Google Sheets

    You can calculate a weighted average in a Pivot Table using a custom formula...

    Summarize Data and Keep the Last Record in Google Sheets

    In Google Sheets, we can summarize data (like sum, average, min, max, count) using...

    How to Retrieve the Last Record in Each Group in Excel

    As part of data analysis, you may need to retrieve the last record from...

    Filter Data with Multi-Select Drop-Downs in Google Sheets

    If you've started using multi-select drop-downs in Google Sheets, you may encounter challenges when...

    More like this

    Calculate Weighted Average in Pivot Table in Google Sheets

    You can calculate a weighted average in a Pivot Table using a custom formula...

    Summarize Data and Keep the Last Record in Google Sheets

    In Google Sheets, we can summarize data (like sum, average, min, max, count) using...

    Filter Data with Multi-Select Drop-Downs in Google Sheets

    If you've started using multi-select drop-downs in Google Sheets, you may encounter challenges when...

    16 COMMENTS

    1. Hey guys. I’m new to SQL and have learned some basics.

      I have a master spreadsheet that I’m pulling data from and placing it into several other worksheets based on someone’s last name.

      =query (Failures,"Select* Where C like 'L%' or C like 'M%' or C like 'N%' or C like 'O%' or C like 'P%' or C like 'Q%'",1)

      Can someone help me figure out how to exclude the data where “none” appears while keeping data where last names start with the letter “N”?

      I think it’s my syntax, but I’m not sure what I’m doing wrong. Thank you!!!

      • Hi, Melissa Watson,

        You can try these modifications.
        1. Replaces multiple LIKE operators with a single MATCH operator.
        2. Use AND to exclude the text “None.”

        Example Formula:

        =query (A1:C,"Select* Where C matches 'L.*|M.*|N.*|O.*|P.*|Q.*' and not(lower(C))='none'",1)

    2. Have a weird problem with the like operator.

      When it is applied to a multiline cell, it doesn’t come out as positive even when I use the wildcard %%. Do you guys know how to fix it?

      • Hi, Francisco,

        Please share the URL of a sample sheet in your next comment/reply. Explain your problem in that Sheet.

        Sometimes the blog comment editor doesn’t post a comment that contains a formula that includes comparison operators.

    3. Hi there,

      Fantastic article, nothing else like it online. Thanks so much for putting it together.

      How would you make the following search not case-sensitive?

      =query(A2:A,"Select A where A Like'"&B1&"'")

      I’ve tried wrapping B1 in double % to no avail.

      Thank you in advance!

    4. Hi, can anyone tell me if I want to extract data using a Query, but exclude certain criteria how to do it. In the above example I do not want “Auckland”, but need “Australia” and “Austria” to appear in my results.

      Your help is appreciated.

      • Hi, Sun Fernando,

        Try the below Query;

        =query(A2:A,"Select A where upper(A) matches 'AUSTRALIA|AUSTRIA'")

        … or Filter.

        =filter(A2:A,REGEXMATCH(upper(A2:A),"AUSTRIA|AUSTRALIA"))

    5. We can use lower (or upper) on both sides of Like operator so that upper, lower or Mixed case be entered, ex:
      =query(A2:A,"Select A where lower(A) like lower('%Land%')")

    6. Hello, How can I use wildcard with reference to SEVERAL cells? B1 and B2 and B3 for example.

      =query(A2:A,"Select A where A Like'"&B1&"'")

    LEAVE A REPLY

    Please enter your comment!
    Please enter your name here

    This site uses Akismet to reduce spam. Learn how your comment data is processed.