The Alternative to SQL IN Operator in Google Sheets QUERY (Also NOT IN)

Published on

Many users coming from SQL wonder if the SQL IN Operator in Google Sheets Query is available. The short answer: Google Sheets QUERY does not support SQL IN or NOT IN operators directly, but there are practical alternatives.

In this guide, we’ll explain how to use the MATCHES operator as an alternative to SQL IN and NOT IN in Google Sheets QUERY. This tutorial is part of the WHERE Clause in Google Sheets QUERY: Logical Conditions Explained hub, which covers all logical operators, comparisons, and condition-building techniques used in QUERY statements.

Why SQL IN Operator Matters

In SQL, the IN operator is used to match a column against multiple values in a list:

SELECT * FROM table WHERE column IN ('Value1', 'Value2', 'Value3');

It allows you to check for multiple possible matches without writing multiple OR conditions.

Since Google Sheets QUERY doesn’t have IN, we can achieve the same result using MATCHES, which supports regular expressions.

Using MATCHES as SQL IN Alternative in Google Sheets QUERY

Suppose you have a table of products in A1:C, where:

  • Column A → Product Names
  • Column B → Unit Price
  • Column C → Stock Availability

And you want to filter products based on a list in column E (your criteria column).

Sample table showing expected results for SQL IN Operator in Google Sheets Query using MATCHES

Option 1: Hardcoded values in QUERY

You can directly list the product names separated by |:

=QUERY(A1:C, "SELECT * WHERE A MATCHES 'Apple|Sweet Melon|Avocado'")

Option 2: Dynamic list using a column reference

If your criteria are in E1:E, combine them using TEXTJOIN:

=QUERY(A1:C, "SELECT * WHERE A MATCHES '" & TEXTJOIN("|", TRUE, E1:E) & "'")
  • TEXTJOIN("|", TRUE, E1:E) combines all values in E1:E into a string separated by |.
  • Example output: Apple|Sweet Melon|Avocado
  • This allows dynamic updates if your criteria change.

Explanation of TEXTJOIN Usage

To verify, enter the following formula in cell F1:

=TEXTJOIN("|", TRUE, E1:E)

This will return the string:

Apple|Sweet Melon|Avocado

You can then use this string in the QUERY formula like this:

=QUERY(A1:C, "SELECT * WHERE A MATCHES '" & F1 & "'")

Alternatively, you can replace F1 with the TEXTJOIN formula directly inside the QUERY:

=QUERY(A1:C, "SELECT * WHERE A MATCHES '" & TEXTJOIN("|", TRUE, E1:E) & "'")

For more details on using cell references and literals in QUERY, see Examples for Using Literals in QUERY in Google Sheets.

Using MATCHES as SQL NOT IN Alternative

To exclude products in a list (SQL NOT IN equivalent), use the NOT operator:

=QUERY(A1:C, "SELECT * WHERE NOT A MATCHES '" & TEXTJOIN("|", TRUE, E1:E) & "'")

Important: The NOT operator must prefix the column identifier, not follow it.

This formula will return all products not listed in your criteria column.

QUERY formula showing SQL NOT IN Operator in Google Sheets Query using MATCHES and TEXTJOIN

SQL IN Operator in Google Sheets Query – Summary

  • SQL IN Alternative: Use MATCHES with a |-separated list or TEXTJOIN for dynamic lists.
  • SQL NOT IN Alternative: Prefix NOT to the column and combine values with TEXTJOIN.
  • Both methods work for single or multiple criteria without manually writing multiple OR conditions.

For a complete guide on logical operators in Google Sheets QUERY, see the hub: WHERE Clause in Google Sheets QUERY: Logical Conditions Explained.

For learning MATCHES operator and string patterns, see: String Matching in QUERY.

Prashanth KV
Prashanth KV
Your Trusted Google Sheets and Excel Expert Prashanth KV 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

Free Monthly Expense Tracker Template in Google Sheets (Dashboard Included)

A monthly expense tracker in Google Sheets helps you record daily expenses, analyze spending...

The Complete Guide to XLOOKUP in Google Sheets (15+ Practical Examples)

The XLOOKUP function largely replaces traditional lookup functions such as LOOKUP, VLOOKUP, and HLOOKUP...

How to Sort and Filter Pivot Tables in Google Sheets (Complete Guide)

Sorting and filtering are two of the most important techniques for analyzing data in...

8 COMMENTS

  1. Hi Prashanth,

    It was helpful, but I may have run into an issue. Am I correct to assume the “matches” operator is case-insensitive, like the match function?

    • The MATCHES substring match is case-sensitive. To make it case-insensitive, use LOWER or UPPER functions.

      Example:

      =query(A1:C,"Select * where lower(A) matches
      'apple|sweet melon|avocado'")

  2. Hello,

    I got a result I want to see, but in TEXTJOIN("|",true,E1:E), what’s the meaning of “|”?

    It’s confusing how it works in the expression.

    • Hi, JunKim,

      In the MATCHES regular expression operator in Query, the “|” (pipe/vertical bar) symbol is to match any of two or more options similar to the OR Spreadsheet function.

      ‘Brazil|Japan’ – To match Brazil or Japan (choice of alternatives)

  3. Very useful post. I use to stumble at this issue many a time. I had to look for workarounds by going for a helper column. But this really sleek.

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.