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.Col1is the first column of the stacked array, whatever its letter in the source.where Col1 is not nullremoves the empty rows that open-ended ranges add.- The last argument
0says the data has no header row.
| Product | Units |
|---|---|
| Chair | 96 |
| Desk | 41 |
| Lamp | 27 |
Common errors
| Error | Cause | Fix |
|---|---|---|
| Unable to parse query string… NO_COLUMN: A | Using A, B with an array | Use Col1, Col2… |
| In ARRAY_LITERAL, an Array Literal was missing values | Ranges have different widths | Make every range the same number of columns |
| Numbers missing in sum() | A column mixes text and numbers | QUERY uses the majority type per column; clean the column |
| Formula parse error | Locale separators | Some 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.