How to Join Two Tables using Query function

Joining two tables using the Query function in Google Sheets involves using the CONCATENATE or "&" operator to combine data from two separate tables into a single table. The Query function will then be used to filter, sort, or manipulate the combined data as needed.

Here's a step-by-step guide on how to join two tables using the Query function in Google Sheets:

  1. Prepare your data: Ensure that you have two separate tables with related information. Make sure the tables have the same number of columns and the columns are in the same order.
  2. Combine the tables: Use the CONCATENATE or "&" operator to join the two tables together. You can do this by creating a new cell and typing in the following formula:

=Table1!A1:C&Table2!A1:C

Replace "Table1" and "Table2" with the appropriate sheet names or ranges for your data. This formula will combine the data from the two tables into a single table.

  1. Apply the Query function: In a new cell, type the following formula to apply the Query function to the combined data:

=QUERY(Table1!A1:C&Table2!A1:C, "SELECT *")

Replace "Table1" and "Table2" with the appropriate sheet names or ranges for your data. This formula will display the combined data in a new table.

  1. Customize your query: You can customize the query by adding additional clauses such as WHERE, ORDER BY, and LIMIT. For example, to filter the combined data based on a specific condition, you can use the following formula:

=QUERY(Table1!A1:C&Table2!A1:C, "SELECT * WHERE C > 1000")

This formula will display data from the combined table where the value in column C is greater than 1000.

Example

Let's say we have two tables in separate sheets: Sheet1 with columns A, B, and C, and Sheet2 with columns A, B, and C.

  1. Combine the tables:

In a new sheet, type the following formula in cell A1:

=Sheet1!A1:C&Sheet2!A1:C

  1. Apply the Query function:

In cell A1, change the formula to:

=QUERY(Sheet1!A1:C&Sheet2!A1:C, "SELECT *")

  1. Customize your query:

For example, if you want to display the combined data where the value in column C is greater than 1000, use the following formula:

=QUERY(Sheet1!A1:C&Sheet2!A1:C, "SELECT * WHERE C > 1000")

This will display the filtered combined data from Sheet1 and Sheet2 in the new sheet.

Did you find this useful?