Simple Comparison Operators in Google Sheets Query

Published on

This tutorial explains how to use simple comparison operators in Google Sheets Query with clear, practical formula examples.

In the QUERY function of Google Sheets, there are seven simple comparison operators available:

<   <=   >   >=   =   !=   <>

These operators are used to compare values in a column against a condition and filter rows accordingly.

In this guide, you’ll find basic, easy-to-follow examples showing how each comparison operator works in Google Sheets QUERY.

Before You Begin: Literals in Google Sheets Query

When using comparison operators in Google Sheets Query, you often need to compare values against literals (the values used in conditions).

The syntax for literals depends on the data type:

  • Numbers → no quotes
  • Text (strings) → must be enclosed in single or double quotes
  • Dates → must be converted to a specific date format

For example, text values should be written like 'First', not First.

This tutorial does not go deep into literal handling. If you want a detailed explanation, see:
Examples of the Use of Literals in Query in Google Sheets

All Seven Simple Comparison Operators in Google Sheets Query

Sample Data

Student marks across three subjects and three terms (First, Second, and Third).

Sample student marks data used to demonstrate comparison operators in Google Sheets QUERY

Below are seven QUERY formulas, each demonstrating one comparison operator.

1. Less Than (<) in Google Sheets Query

=QUERY(A1:E, "SELECT * WHERE C < 95", 1)

2. Greater Than (>) in Google Sheets Query

=QUERY(A1:E, "SELECT * WHERE D > 80", 1)
Google Sheets QUERY example using a simple comparison operator to filter rows where marks are greater than 80

3. Less Than or Equal To (<=) in Google Sheets Query

=QUERY(A1:E, "SELECT * WHERE D <= 80", 1)

4. Greater Than or Equal To (>=) in Google Sheets Query

=QUERY(A1:E, "SELECT * WHERE E >= 80", 1)

5. Equal To (=) in Google Sheets Query

=QUERY(A1:E, "SELECT * WHERE B = 'First'", 1)

6. Not Equal To (<>) in Google Sheets Query

=QUERY(A1:E, "SELECT * WHERE B <> 'First'", 1)

7. Not Equal To (!=) in Google Sheets Query (Equivalent)

=QUERY(A1:E, "SELECT * WHERE B != 'First'", 1)

Both <> and != work identically and represent the not equal to comparison operator.

Comparing Against Empty Cells (NULL)

In Google Sheets QUERY, NULL values cannot be compared using = or !=.

Instead, use:

=QUERY(A1:E, "SELECT * WHERE B IS NOT NULL", 1)

Or:

=QUERY(A1:E, "SELECT * WHERE B IS NULL", 1)

This is essential when working with incomplete datasets.

Using Multiple Comparison Operators

To combine multiple conditions—either in the same column or across different columns—use logical operators such as AND, OR, and NOT in the WHERE clause.

For a complete and structured explanation of logical conditions, comparison operators, and condition-building patterns, refer to the hub:

WHERE Clause in Google Sheets QUERY: Logical Conditions Explained

Complex Comparison Operators in Google Sheets Query

In addition to simple comparison operators, Google Sheets QUERY also supports string-based (complex) comparison operators.

These are primarily used for text matching:

  • CONTAINS
  • MATCHES
  • STARTS WITH
  • ENDS WITH
  • LIKE

These operators are explained in detail here:
String Matching in QUERY

Note: Some of these operators can also be used with numbers, but their primary purpose is string comparison.

Conclusion

The simple comparison operators in Google Sheets Query<, <=, >, >=, =, !=, and <>—form the foundation of filtering data with the QUERY function.

Key takeaways:

  • Use simple operators for numeric, text, and date comparisons
  • Handle NULL values with IS NULL or IS NOT NULL
  • Combine conditions using logical operators
  • Use complex operators when pattern matching is required

With these fundamentals, you can confidently build powerful QUERY filters in Google Sheets.

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

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...

Pivot Table Formatting, Output & Special Behavior in Google Sheets

Pivot Tables in Google Sheets are powerful—but they can get tricky once you move...

2 COMMENTS

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.