Google Sheets Query or Statement? Clear Answer

How-to basics · Updated November 23, 2026

Google Sheets uses QUERY, a built-in function, not a separate “statement” or scripting command. It is a formula you type into a cell (like =QUERY(A1:D10, "select * where B > 100")) that returns filtered, sorted, or aggregated data from a range. There is no standalone “statement” syntax in the Sheets interface; everything goes through the QUERY function or the related QUERY menu under Data > Query.

Background: Where QUERY Comes From

Google Sheets QUERY is modeled on the Google Visualization API Query Language, a SQL-like syntax used to query Google Charts data tables. Google introduced QUERY to Sheets in 2012, giving spreadsheet users a way to perform database-style operations without writing scripts. It is one of the most powerful functions in Sheets because it can replace many combinations of FILTER, SORT, UNIQUE, and SUMIFS in a single formula.

Excel has no direct equivalent. Excel offers Power Query (Get & Transform) under the Data tab, but that is a separate tool for importing and transforming data, not a cell function. Excel also has the older DSUM, DCOUNT, and other database functions, plus dynamic array functions like FILTER and SORT (Excel 2021/Microsoft 365). But if you want SQL-like syntax in Excel, you would need to use Power Query’s M language or VBA. So the term “query” in Sheets specifically refers to the QUERY function.

How the QUERY Function Works

The syntax is simple: =QUERY(data, query, [headers]). The first argument is the range (e.g., A1:C100). The second is a string containing the query in double quotes. The optional third tells Sheets how many header rows to treat as labels (default is 1).

Example: with sales data in A1:D20 (columns: Date, Product, Region, Sales), to get total sales per region for the West region only, you would write:

=QUERY(A1:D20, "select C, sum(D) where B = 'West' group by C", 1)

This returns two columns: Region and sum of Sales, filtered to West. The query language supports select, where, group by, order by, limit, offset, label, format, and pivot. You can also use arithmetic and functions like avg(), count(), max(), min(), and year().

One common mistake is forgetting to enclose the query in double quotes. Another is using single quotes inside the query string—Sheets requires double quotes for the whole query, and single quotes for text values inside it (like ‘West’). If you need to reference a cell value, you concatenate with &: =QUERY(A1:D20, "select * where C = '"&E1&"'", 1).

QUERY vs. Other Functions: When to Use Which

QUERY is powerful but not always the best choice. For simple filtering, FILTER is often faster and easier to read. For sorting, SORT is straightforward. For unique values, UNIQUE is clearer. QUERY shines when you need to combine operations—filter, group, aggregate, and sort in one go—or when you want to use SQL-like syntax you already know.

  • Use QUERY when you need multiple operations in one formula, like grouping by month and summing sales, or when you want to pivot data.
  • Use FILTER for simple row filtering based on one or more conditions.
  • Use SORT for basic sorting by one or more columns.
  • Use UNIQUE to extract distinct values from a column.
  • Use SUMIFS/COUNTIFS for conditional sums/counts without returning a data table.

Example: If you just want the rows where Sales > 100, =FILTER(A1:D20, D1:D20>100) is simpler than QUERY. But if you also want to group by product and show total sales, QUERY is the only single-function way.

Common Problems and How to Fix Them

Many users run into the same issues with QUERY. Here are the most frequent and their solutions:

  • #VALUE! error – Usually means the query string is malformed. Check for missing quotes, commas, or misspelled column letters. Also, ensure column references use letters, not numbers (e.g., A, B, not 1, 2).
  • #REF! error – The range is invalid or deleted. Re-select the range.
  • #N/A error – Often means no data matches the where condition, or you used a column label that doesn’t exist.
  • Blank rows appearing – QUERY includes blank rows if they are in the range. Use where A is not null to filter them out.
  • Text vs. number mismatch – If a column contains numbers stored as text, comparisons like >100 may fail. Use value(A) in the query to convert, or clean the data.
  • Header row issues – If your data has no headers, set the third argument to 0: =QUERY(A1:D20, "select *", 0). If you have multiple header rows, you may need to adjust the range to start after them.

Another common misconception is that QUERY can edit data. It cannot—it only returns a new table. To change the original data, you must edit the source cells or use a script.

Comparing QUERY to Excel’s Power Query

People often confuse Google Sheets QUERY with Excel’s Power Query because both have “query” in the name. They are fundamentally different:

  • Google Sheets QUERY is a formula that returns a dynamic array. It recalculates when the source data changes. It lives in a cell and can be used in other formulas.
  • Excel Power Query is a data transformation tool accessed via Data > Get & Transform Data. It creates a query that can be refreshed, but the output is typically loaded to a table or worksheet. It is not a formula; it is a separate interface with its own language (M).

If you are an Excel user looking for a QUERY-like function, the closest are FILTER, SORT, and UNIQUE (Excel 2021/Microsoft 365). For grouping and aggregation, you might use SUMIFS or pivot tables. Excel has no direct SQL-like function in a cell.

Cost and Availability

Google Sheets QUERY is free for all users—personal Google accounts and Google Workspace (formerly G Suite) accounts. There is no premium tier that unlocks QUERY. The only limitation is that QUERY may be slower on very large datasets (hundreds of thousands of rows) because it recalculates on every edit. For most business use, performance is fine.

Excel’s Power Query is included in all modern versions of Excel (2016, 2019, 2021, Microsoft 365). There is no extra cost. However, the dynamic array functions (FILTER, SORT, UNIQUE) require Excel 2021 or Microsoft 365. Older versions like Excel 2016 do not have them.

Safety and Best Practices

QUERY is safe to use—it does not modify your data. However, there are a few things to keep in mind:

  • Always test on a copy if you are new to QUERY, especially when using label or format clauses that change the output.
  • Be careful with external data – If you use QUERY with data imported from other sources, ensure the data is clean and consistent.
  • Watch for circular references – If your QUERY formula references a range that includes the cell where the formula is placed, you will get a circular dependency error.
  • Use absolute references when dragging formulas to avoid range shifts.

For financial calculations, always double-check the arithmetic. For example, if you use QUERY to sum sales, verify against a manual sum. QUERY does not round or adjust numbers; it returns exact values.

Alternatives to QUERY in Google Sheets

If QUERY feels too complex, you have several alternatives:

  • Pivot Tables – Built-in tool for grouping and summarizing data. No formula needed.
  • FILTER + SORT + UNIQUE – Combine these functions for simple transformations.
  • Apps Script – Write custom JavaScript to query data programmatically. This is a true “statement” approach, but it requires coding.
  • Google Sheets API – For developers, you can run queries via the API, but that is outside the spreadsheet UI.

For most users, QUERY is the best balance of power and simplicity. It is not a statement, but it is the closest thing to a SQL query you can type directly into a cell.

Frequently Asked Questions

Is QUERY the same as SQL? No, but it is very similar. The Google Visualization API Query Language shares many keywords with SQL (SELECT, WHERE, GROUP BY, ORDER BY), but it has limitations: no JOINs, no subqueries, and no UPDATE/DELETE. It is read-only.

Can I use QUERY to combine two sheets? Yes, but only if you use the IMPORTRANGE function inside the QUERY data range. For example: =QUERY(IMPORTRANGE("url", "Sheet1!A:C"), "select * where Col1 is not null"). Note that column references in the query use Col1, Col2, etc., not letters, when using IMPORTRANGE.

Why does my QUERY show “#VALUE!” when I use a cell reference? Because you need to concatenate the cell value into the query string. Use & and wrap the cell reference in single quotes if it’s text. Example: =QUERY(A1:D20, "select * where C = '"&E1&"'", 1).

Does QUERY work on Mac or mobile? Yes, QUERY works in Google Sheets on any platform (Windows, Mac, Chrome OS, Android, iOS) because it runs on Google’s servers. The interface differs slightly on mobile, but the function is the same.

Can I use QUERY to return a single value? Yes, but you might need to wrap it in INDEX or use a specific select. For example, =QUERY(A1:D20, "select sum(D) where C='West'", 0) returns a single cell. If you get a column of data, use =INDEX(QUERY(...),1,1) to get the first value.

Is there a way to learn QUERY faster? Use the built-in Google Sheets function help (press F1 and search for QUERY), or try the Query function with the Google Visualization API reference. Practice with small datasets and use the “insert > function” menu to see the 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.