STARTS WITH and NOT STARTS WITH Prefix Match in Google Sheets Query

Published on

The STARTS WITH is a string comparison operator for prefix match in the Google Sheets Query function. What is its role?

This complex comparison operator helps users to filter rows containing partial matches.

For example, it helps u to filter names that start with or do not start with a specific letter(s) or strings in a column.

It’s a detailed Google Sheets tutorial on using the STARTS WITH prefix match in Google Sheets Query.

Also, you can learn how to negate it using the NOT logical operator in Query.

Introduction to String Comparison in Google Sheets Query

In the Query Where clause, we can use different string comparison operators to filter rows that match a specified condition.

The STARTS WITH is one such ‘complex’ spring comparison operator.

Here are the other popular string comparison operators.

How to Use the STARTS WITH Prefix Match in Google Sheets Query

In the below sample data, I am applying the Query STARTS WITH Prefix match in the second column.

The first column contains employee names, and the second column their assigned department.

I want to filter all the names (persons), who are working in the engineering department.

Starts with Prefix Match in Google Sheets Query

Formula:

=Query(A1:B,"Select * Where B Starts with 'Engineering'",1)

This formula will return all the rows containing the prefix “Engineering” in the second column.

It’s not the only complex string comparison operator in Google Sheets Query for this type of filtering data.

We can use the MATCHES regular expression match with Query as follows.

=Query(A1:B,"Select * Where B matches 'Engineering.*'",1)

Now here is a different scenario.

I want to filter all the rows that do not start with “Engineering” in the second column.

Let’s see how to do that.

How to Use NOT STARTS WITH Prefix Match in Google Sheets Query

If we use the above same sample data, the formula would be like this.

=Query(A1:B,"Select * Where not B Starts with 'Engineering'",1)

Please see the positioning of the Not logical operator. It should be before the column identifier.

Can we apply the same logic and use the MATCHES instead of NOT STARTS WITH in the Query function?

You can. Here you go.

=Query(A1:B,"Select * Where not B matches 'Engineering.*'",1)

The prefix match is in a text column in all the above examples. Of course, that justifies the usage of a string comparison operator.

 Does this work in a number or date column?

I think such a type of comparison may not come in real-life use.

Still, out of curiosity, let’s see whether this string comparison operator may or may not work in a number column first.

Query String Comparison in a Number or Date Column

STARTS WITH Example in Number Column:

In cell range A2:A, I have numbers from 100 to 150 in sequential order.

The below formula that uses the STARTS WITH prefix match would return the numbers 110 to 119.

=query(A1:A,"Select * Where A Starts with 11",1)

NOT STARTS WITH Example in Number Column:

If you negate the Starts With, the result would be numbers from 100 to 109 and 120 to 150.

=query(A1:A,"Select * Where not A Starts with 11",1)

STARTS WITH String Comparison Operator in a Date Column

It won’t work in a date column.

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.

How to Create a Searchable Table in Excel Using the FILTER Function

Finding specific records, or rows containing the required information, is straightforward in Excel using...

Time Sequences in Excel by Minute, Hour, or Second Increments

Creating time sequences, whether by hour, minute, or second increments in Excel, can be...

Finding Most Frequent Text in Excel with Dynamic Array Formulas

Looking to identify the most frequently occurring text in Excel? You can do this...

Hierarchical Numbering Sequences in Excel

Creating hierarchical numbering sequences in an Excel spreadsheet can significantly improve the way you...

More like this

XMATCH Row by Row: Finding Values Across a Range in Google Sheets

Using the BYROW function with XMATCH in Google Sheets allows us to match values...

Limit Formula Expansion to a Specific Row in Google Sheets

In this tutorial, I’ll explain how to limit the expansion of an array formula...

3-D Referencing Structured Data Tables in Google Sheets

When you have several tables within a single sheet—not across multiple sheets in a...

10 COMMENTS

  1. What if

    =Query(A1:A7,"Select * Where A starts with '1.*|6.*'",1)

    or

    =Query(A1:A7,"Select * Where A starts with 1.*|6.*",1)

  2. Hi Prasanth,

    Excellent information right there, and it was just what I needed.

    I do, however, need some more information. How do you extract data beginning with numbers in general?

    That is to say, anything that doesn’t start with a letter.

    Hopefully, this is clear.

    Thanks in advance.

  3. Why is it not working with the following one:

    =Query(A1:A7,"Select * Where not A Starts with 'One Test|Two Tests'",1)

    Data in A1:A7:

    One Test
    Two Tests
    3
    4
    5
    6
    7

    Please, can you update this post to show how to do it with multiple starting with strings?

  4. What about OR to include multiple queries in one? Can’t find a way that works. Trying to do multiple area codes that are in one city.

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.