Google Sheets Query Not Equal: Syntax & Examples

How-to basics · Updated November 23, 2026

In Google Sheets, the QUERY function does not use the standard <> operator for “not equal” in its SQL-like syntax; instead, you use != or <> inside the query string, but the correct and most reliable form is !=. For example, =QUERY(A1:C10, "select * where B != 'Closed'") returns all rows where column B is not exactly “Closed”.

Understanding the QUERY Function

QUERY is one of Google Sheets’ most powerful functions. It lets you run a SQL-like query against a range of data. The basic syntax is:

=QUERY(data, query, [headers])
  • data – the range to query (e.g., A1:D100).
  • query – a string in double quotes containing the SQL-like command.
  • headers – optional; the number of header rows at the top of the data.

The query string can include select, where, order by, group by, limit, and more. The where clause filters rows based on conditions, and that’s where you use “not equal”.

How to Write “Not Equal” in QUERY

In Google Sheets’ QUERY, you can use either != or <>. Both are valid, but != is more commonly used and less prone to confusion with HTML entities. Here are examples for different data types:

  • Text: where B != 'Closed' – matches rows where column B is not exactly “Closed” (case-insensitive by default).
  • Numbers: where C != 100 – matches rows where column C does not equal 100.
  • Dates: where D != date '2025-01-01' – matches rows where column D is not January 1, 2025.
  • Booleans: where E != FALSE – matches rows where column E is not FALSE (i.e., TRUE).

Example with a full formula: If your data is in A1:C10 with headers in row 1, and you want all rows where column B is not “Pending”, use:

=QUERY(A1:C10, "select * where B != 'Pending'", 1)

Comparing QUERY to Other Methods

While QUERY is powerful, there are simpler alternatives for filtering out a value:

  • FILTER function: =FILTER(A1:C10, B1:B10 <> "Pending") – easier for simple conditions, but QUERY handles complex logic and grouping more elegantly.
  • Filter views: Use Data > Create a filter, then uncheck the values you don’t want – no formula needed.
  • Conditional formatting: Not for filtering data, but for highlighting rows that don’t match a value.

QUERY shines when you need to combine conditions, aggregate data, or sort results. For instance, you can do where B != 'Pending' and C > 50 in one line.

Common Pitfalls and Errors

Users often run into issues when using “not equal” in QUERY. Here are the most frequent:

  • Using single quotes inside the query string: The entire query is in double quotes, so text values must use single quotes. For example, "where B != 'Closed'" is correct; "where B != "Closed"" breaks the formula.
  • Case sensitivity: QUERY’s text comparisons are case-insensitive by default. If you need case-sensitive matching, you must use EXACT() inside a QUERY, which is complex. For most cases, case-insensitivity is fine.
  • Blank cells: != treats blank cells as not equal to a value, so they are included. If you want to exclude blanks, add and B is not null.
  • Using <> in some locales: In some European locales, the comma in formulas is replaced by a semicolon, but the operators stay the same. Always use commas in the function arguments.

Example to exclude blanks: =QUERY(A1:C10, "select * where B != 'Pending' and B is not null", 1)

Advanced Usage: Combining with Other Conditions

You can combine “not equal” with other operators to create powerful filters:

  • AND: where B != 'Pending' and C > 100
  • OR: where B != 'Pending' or C > 100
  • NOT with IN: where B not in ('Pending', 'Review') – this is a cleaner way to exclude multiple values.
  • Using LIKE: where B not like 'P%' – excludes rows where B starts with “P”.

Example with NOT IN:

=QUERY(A1:C10, "select * where B not in ('Pending', 'Review')", 1)

QUERY vs. Excel’s Equivalent

Excel does not have a direct QUERY function. The closest is the FILTER function (Excel 365) or the older Advanced Filter. In Excel, you would write:

=FILTER(A1:C10, B1:B10 <> "Pending")

Or use a pivot table with a filter. Google Sheets’ QUERY is more similar to SQL, which makes it more flexible for complex data manipulation. If you’re migrating from Excel, expect a learning curve.

Performance and Best Practices

QUERY can handle large datasets, but it’s not infinitely fast. For thousands of rows, it’s fine. For hundreds of thousands, consider using pivot tables or Google BigQuery. Best practices:

  • Limit the range to the actual data, not entire columns (e.g., A1:C1000, not A:C).
  • Use limit if you only need a few rows.
  • Combine multiple conditions with parentheses to ensure correct logic.
  • Use label to rename columns in the output.

Example with limit and label:

=QUERY(A1:C10, "select A, B where B != 'Pending' limit 5 label A 'Name'", 1)

Frequently Asked Questions

Can I use <> in Google Sheets QUERY? Yes, both <> and != work. However, != is more common and avoids potential issues with HTML encoding if you’re copy-pasting.

How do I exclude multiple values in QUERY? Use the not in operator: where B not in ('Value1', 'Value2'). This is cleaner than chaining multiple != with and.

Why does my QUERY return blank rows when using !=? Because blank cells are not equal to the specified value, so they pass the filter. Add and B is not null to exclude blanks.

Is QUERY case-sensitive? No, by default text comparisons are case-insensitive. If you need case-sensitive, you’d have to use a helper column with EXACT or use a script.

Can I use “not equal” with numbers and dates? Yes, just write the number directly or use date 'YYYY-MM-DD' for dates. Example: where C != 100 or where D != date '2025-01-01'.

What’s the difference between QUERY and FILTER? QUERY is more powerful for complex logic and aggregation, but FILTER is simpler and often faster for basic filtering. Use FILTER for simple conditions, QUERY when you need to group, sort, or use SQL-like syntax.

Related

Try it: the Date Difference Calculator: days, months, years and weekdays between two dates, with the DATEDIF formulas.

More in How-to basics

Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources

Spotted an error in this guide? Let us know.