How to Query From Another Sheet using Query function

To query data from another sheet using the Query function in Google Sheets, you should use the IMPORTRANGE function within the Query function to import the data from the other sheet. Here's a step-by-step guide on how to do this:

  1. First, you need the URL of the Google Sheet that contains the data you want to query. If the data is in the same Google Sheet but on a different tab, you can skip this step.
  2. Use the IMPORTRANGE function to import the data from the other sheet. The syntax for the IMPORTRANGE function is:
IMPORTRANGE("spreadsheet_url", "sheet_name!cell_range")
  1. Use the Query function to query the data from the other sheet. The syntax for the Query function is:
QUERY(data, query, [headers])

Example

Let's assume you have two sheets in the same Google Sheets document:

The data in Sheet1 is as follows:

Name Age Gender
Alice 27 F
Bob 32 M
Carol 29 F
Dave 24 M

In Sheet2, you want to display the names and ages of all females. To do this, use the following formula:

=QUERY(IMPORTRANGE("", "Sheet1!A1:C4"), "SELECT Col1, Col2 WHERE Col3 = 'F'")

This will display the following results in Sheet2:

Name Age
Alice 27
Carol 29

Note: If the data is in another Google Sheet, replace "" in the IMPORTRANGE function with the URL of that Google Sheet.

Did you find this useful?