FormulaCraft

How to use QUERY with WHERE, AND, OR in Excel and Google Sheets

Topic:QUERY (Google Sheets SQL)

Heads up: Excel and Google Sheets do this differently.

Excel
=FILTER(A2:C10,(B2:B10="Electronics")+(B2:B10="Clothing"))
Google Sheets
=QUERY(A1:C10,"SELECT A, B, C WHERE (B = 'Electronics' OR B = 'Clothing') AND C > 500",1)

Try it with your data

Edit the grid or formula, then run it through a real spreadsheet engine — no signup.

Sample data — click any cell to edit

Runs server-side · free · no signup

Step by step

  1. 1Confirm your data layout: Order ID (A), Category (B), Amount (C) with headers in row 1.
  2. 2Click a destination cell — such as E1 — and enter: =QUERY(A1:C10,"SELECT A, B, C WHERE (B = 'Electronics' OR B = 'Clothing') AND C > 500",1).
  3. 3The WHERE clause filters to rows where Category is Electronics OR Clothing, AND the Amount exceeds 500.
  4. 4Parentheses control precedence just as in SQL — wrap OR conditions in parentheses when combining with AND to avoid ambiguity.
  5. 5To negate a condition use NOT: WHERE NOT (B = 'Electronics') excludes that category entirely.

Tips

Need it for your exact data?

Describe your columns in plain English and get the precise formula for your sheet, with the right Excel or Sheets syntax.

Frequently asked

Does QUERY support NOT LIKE or NOT IN?

QUERY supports NOT with conditions: WHERE NOT B = 'Electronics'. For a list exclusion, chain them: WHERE B != 'Electronics' AND B != 'Clothing'. There is no native IN(...) operator in the Google Visualization API query language.

Why does my WHERE clause return no results even though the data matches?

Case sensitivity is the most common cause. QUERY string matching is case-sensitive by default. Ensure 'Electronics' matches the exact capitalisation in your data, or use LOWER() in the formula and LOWER(B) = 'electronics' in the query string.

Can I combine WHERE with GROUP BY?

Yes. WHERE always comes before GROUP BY in the query string: SELECT B, SUM(C) WHERE C > 500 GROUP BY B. QUERY respects the same clause order as SQL.

More on QUERY (Google Sheets SQL)

See all →

Formulas used

Written and reviewed by FormulaCraft Team. Each formula on this page is run through our verification engine before publishing.

Last reviewed: