QUERY from Another Sheet or Spreadsheet in Google Sheets

QUERY doesn’t care where its data lives. Point the first argument at another tab and it works the same as on the current one; wrap that argument in IMPORTRANGE and it reads another spreadsheet. The details that trip people up are the quotes around the tab name, the blank rows of whole-column ranges and the column names when the data comes through IMPORTRANGE or from several tabs at once.

Tested in Google Sheets. On November 11, 2026 we queried a second tab called “Week 8 data”, with spaces in its name on purpose, and recorded each result and error message. How we test

Our QUERY formula generator writes these formulas for you: choose “In another tab” or “In another spreadsheet” and it adds the quotes, the IMPORTRANGE and the Col1 names.

From another tab

The “Week 8 data” tab had items in A, a category in B and a quantity in C, with headers in row 1:

=QUERY('Week 8 data'!A1:C6, "select A, C where C > 10", 1)

It returned Desk 12, Chair 20 and Paper 50, with the headings Item and Qty. Everything else works as usual; "select A, C where B = 'Furniture' order by C desc" returned Chair 20, Desk 12, Lamp 8.

The column letters in the query are the letters of the other tab, not of the sheet where you type the formula.

Quotes around the tab name

  • A tab name with spaces or symbols goes in single quotes: 'Week 8 data'!A1:C6. Without them, =QUERY(Week 8 data!A1:C6, "select A", 1) was a formula parse error.
  • A simple name such as Sales!A1:C6 needs no quotes. Adding them did no harm: Google Sheets accepted 'Untitled'!A1:A3 and simply removed the quotes it didn’t need.
  • If the name contains an apostrophe, double it inside the quotes. We created a tab called Ana’s data, and 'Ana''s data'!A1:A2 read it correctly.

Whole columns and blank rows

A range such as 'Week 8 data'!A:C picks up new rows automatically, but it also includes every empty row of the tab. In our test, "select A, C order by C" on that range returned 14 empty rows before the five items, because blanks sort first. Adding where A is not null fixed it:

=QUERY('Week 8 data'!A:C, "select A, C where A is not null order by C", 1)

From another spreadsheet: IMPORTRANGE

IMPORTRANGE brings a range from another file, and QUERY can work on the result:

=QUERY(IMPORTRANGE("spreadsheet-url-or-id", "'Week 8 data'!A1:C6"), "select Col1, Col3 where Col3 > 10", 1)

Two things change:

  1. Columns are named by position. Col1 is the first column of the imported range, not column A of the sheet. When we imported B1:C6, column B became Col1 and C became Col2: "select Col2 where Col1 = 'Office'" returned 5 and 50, the two Office quantities.
  2. The first connection needs permission. Google’s IMPORTRANGE help page says you must allow access the first time a file imports from another one. In our earlier tests, a formula that tried to read another file before that step returned Please use a desktop web browser to connect this sheet. Open the sheet in a browser, click the cell and choose Allow access.

Found in testing: when IMPORTRANGE read from the same file, both select A, C and select Col1, Col3 worked and returned the same rows. We could only test that case through our tools, because a different file needs the Allow access click first. Col1 notation worked every time, so it is the safe choice for any QUERY built on IMPORTRANGE.

If IMPORTRANGE itself fails, see IMPORTRANGE errors and fixes.

From several tabs at once

To query two tabs as one table, stack them with curly braces and a semicolon, then use Col1 notation, because a stacked array has no column letters:

=QUERY({Jan!A2:B; Feb!A2:B}, "select Col1, count(Col2) where Col1 is not null group by Col1")

We tested the pattern by stacking the “Week 8 data” tab on itself, from row 2 so the headers stayed out, with open-ended ranges:

=QUERY({'Week 8 data'!A2:C; 'Week 8 data'!A2:C}, "select Col2, count(Col1) where Col1 is not null group by Col2")

It returned Furniture 6 and Office 4, double the real counts as expected from stacking the same data twice. Without where Col1 is not null, the result gained an extra group for the empty rows, with a blank name and a count of 0. And with letters instead of Col numbers, "select A" on stacked data returned #N/A.

Because the stacked ranges start below the header row, the result has no proper headings: the count column was just called “count”.

Summary

Data in… First argument Columns in the query
The same tab A1:E100 A, B, C…
Another tab 'Tab name'!A1:E100 A, B, C… of that tab
Another spreadsheet IMPORTRANGE("url", "'Tab name'!A1:E100") Col1, Col2… from the first imported column
Several tabs {'Tab 1'!A2:E; 'Tab 2'!A2:E} Col1, Col2…

Related guides