Analistable

How to use QUERY with multiple ranges in Google Sheets

By the Analistable team · Updated · 2 min read

Stack the ranges inside QUERY's first argument: =QUERY({Jan!A2:C; Feb!A2:C; Mar!A2:C}, "select Col2, sum(Col3) where Col1 is not null group by Col2", 0). Because the data is an array rather than a sheet range, columns must be called Col1, Col2, Col3 — not A, B, C — and every range must have the same number of columns.

Part of our guide: How to combine data in Google Sheets

The pattern

=QUERY({Jan!A2:C; Feb!A2:C; Mar!A2:C},
  "select Col2, sum(Col3)
   where Col1 is not null
   group by Col2
   order by sum(Col3) desc
   label sum(Col3) 'Units'", 0)
  • {range; range} stacks ranges vertically (a semicolon means “new rows”). VSTACK works too.
  • Col1 is the first column of the stacked array, whatever its letter in the source.
  • where Col1 is not null removes the empty rows that open-ended ranges add.
  • The last argument 0 says the data has no header row.
Result: units by product across three tabs
ProductUnits
Chair96
Desk41
Lamp27

Common errors

QUERY errors with stacked ranges
ErrorCauseFix
Unable to parse query string… NO_COLUMN: AUsing A, B with an arrayUse Col1, Col2…
In ARRAY_LITERAL, an Array Literal was missing valuesRanges have different widthsMake every range the same number of columns
Numbers missing in sum()A column mixes text and numbersQUERY uses the majority type per column; clean the column
Formula parse errorLocale separatorsSome locales use \ between columns in { }

Ranges from other files

Replace a tab range with IMPORTRANGE("url", "Tab!A2:C"). QUERY over IMPORTRANGE also uses Col1 notation. See combining multiple IMPORTRANGE formulas.

What QUERY can't do

QUERY works on one table at a time, so it can't join two tables on a key. To combine tables by ID, use lookups as shown in linking two Google Sheets, or stack and group as above when the tables share columns.

To ask questions like this in plain language across Sheets and Excel files, Analistable writes the SQL (which can join) for you.

More useful patterns

Filter by a date range:
=QUERY({Jan!A2:C; Feb!A2:C}, "select * where Col1 >= date '2026-01-15' and Col1 < date '2026-02-15'", 0)

Count rows per tab (add the tab name first with HSTACK):
=QUERY(VSTACK(HSTACK(IF(Jan!A2:A<>"","Jan",), Jan!A2:C), HSTACK(IF(Feb!A2:A<>"","Feb",), Feb!A2:C)),
  "select Col1, count(Col2) where Col2 is not null group by Col1", 0)

Dates in QUERY need the date 'yyyy-mm-dd' literal. In the second formula, the stacked array starts with the tab name, so the original columns shift one to the right (Col2, Col3…). Depending on your version, the IF inside HSTACK may need ARRAYFORMULA around it.

Frequently asked questions

Can Google Sheets QUERY use multiple ranges?
Yes. Stack them in an array, such as {Sheet1!A2:C; Sheet2!A2:C}, and refer to columns as Col1, Col2 and so on.
Why does QUERY say NO_COLUMN?
With an array as the data, columns must be referenced as Col1, Col2… rather than A, B.
Can QUERY join two tables?
No. Use VLOOKUP or XLOOKUP to combine tables by a key.

Related guides