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

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

The STARTS WITH operator is a string comparison operator used for prefix matching in the Google Sheets QUERY function. Understanding its role is essential when you want to filter rows based on how text begins in a column.

This complex string comparison operator allows you to filter rows that contain partial text matches at the beginning of a string. In other words, it helps you include or exclude values based on a specific starting pattern.

For example, you can use it to filter names that start with or do not start with a specific letter, word, or substring in a column.

Both STARTS WITH and NOT STARTS WITH are explained here in detail as part of the String Matching in Google Sheets QUERY guide.

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

In the sample data below, the STARTS WITH prefix match is applied to the second column.

  • The first column contains employee names
  • The second column contains their assigned departments
Starts with Prefix Match in Google Sheets Query

Requirement

Filter all employees who are working in departments that start with “Engineering”.

Formula

=QUERY(A1:B, "SELECT * WHERE B STARTS WITH 'Engineering'", 1)

Result Explanation

This formula returns all rows where the department name starts with “Engineering”, including values such as:

  • Engineering – Civil
  • Engineering – Mechanical
  • Engineering – Electrical

This makes Starts with Prefix Match in Google Sheets Query ideal when your data contains structured naming patterns.

Why Use STARTS WITH Instead of LIKE or MATCHES?

While STARTS WITH is not the only string comparison operator available, it is often the best choice for prefix-based filtering.

You can also use:

  • MATCHES (regular expressions)
  • LIKE (pattern matching)

However, for simple prefix matching, STARTS WITH offers better performance and cleaner formulas.

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

Now let’s look at the opposite scenario.

Requirement

Filter all rows where the department does NOT start with “Engineering”.

Formula

=QUERY(A1:B, "SELECT * WHERE NOT B STARTS WITH 'Engineering'", 1)

Important Note

Pay attention to the position of the NOT operator.
It must be placed before the column identifier, not before STARTS WITH.

✅ Correct

WHERE NOT B STARTS WITH 'Engineering'

❌ Incorrect

WHERE B NOT STARTS WITH 'Engineering'

Case Sensitivity in STARTS WITH Query

By default, string matching in Google Sheets Query is case-sensitive.

To make it case-insensitive, use scalar functions such as LOWER() or UPPER().

Example (Case-Insensitive Prefix Match)

=QUERY(A1:B, "SELECT * WHERE LOWER(B) STARTS WITH 'engineering'", 1)

This formula returns rows that start with:

  • Engineering
  • engineering
  • ENGINEERING

…regardless of the text case.

Note: If you use LOWER(), ensure the comparison text is also in lowercase.
If you use UPPER(), use uppercase text instead.

Using Cell References with STARTS WITH in QUERY

Instead of hardcoding the prefix inside the formula, you can place it in a cell and reference it dynamically.

For example, if cell D1 contains the prefix:

Engineering

You can use:

=QUERY(A1:B, "SELECT * WHERE B STARTS WITH '"&D1&"'", 1)

This approach makes your formulas more flexible and reusable, especially in dashboards and dynamic reports.

A detailed explanation is available here:
How to Use Cell Reference in Google Sheets Query

Conclusion

The Starts with Prefix Match in Google Sheets Query is a powerful and efficient way to filter data based on how text begins in a column.

Key Takeaways:

  • Use STARTS WITH for fast and clean prefix matching
  • Use NOT STARTS WITH to exclude specific prefixes
  • Prefer STARTS WITH over LIKE or MATCHES for prefix matching, as it avoids wildcard or regex-style pattern processing.
  • Apply LOWER() or UPPER() for case-insensitive matching
  • Use cell references for dynamic and scalable formulas

Mastering this operator will significantly improve your ability to work with structured text data in Google Sheets.

Prashanth K V
Prashanth K V
Your Trusted Google Sheets and Excel Expert Prashanth K V is a Diamond Product Expert in Google Sheets, officially recognized by Google for his contributions to the Docs Editors Help Community and featured in the Google Product Experts Directory. Explore his blog to learn advanced formulas, automation tips, and problem-solving techniques to elevate your spreadsheet skills.

Top Discussions

More like this

How to Build a Dynamic Nonogram Clue Generator in Google Sheets

Over the past few months, I've built a couple of games in Google Sheets,...

Carpool Cost Splitter & Rotation Tracker in Google Sheets (Free Template)

Managing a carpool can be difficult, especially when you need to track whose vehicle...

How to Build a Road Trip Fuel Cost Splitter Formula in Google Sheets

Need a fair formula to split fuel costs among travelers on a long road...

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.