How to Join Two Tables in Google Sheets Query?

Joining two tables in Google Sheets Query is a simple process. To join two tables, you first need to use the Query function to select the data from the two tables and then use the JOIN command to combine the two tables. The syntax of the JOIN command is JOIN(table1, table2, join_type, join_criteria). The join_type argument defines how the two tables should be combined and the join_criteria argument defines the criteria for joining the two tables. The JOIN command can also be used to merge data from multiple tables into one table.


Often you may want to use the QUERY() function in Google Sheets to join two tables together.

Unfortunately, a JOIN() function does not exist within the QUERY() function, but you can use the following formula as a workaround to join two tables together:

=ArrayFormula(
   {
     A2:B6,
     vlookup(A2:A6,D2:E6,COLUMN(Indirect("R1C2:R1C"&COLUMNS(D2:E6),0)),0)
   }
)

This particular formula performs a left join on the tables located in the ranges A2:B6 and D2:E6.

The following example shows how to use this formula in practice.

Example: Join Two Tables in Google Sheets

Suppose we have the following two tables in Google Sheets that contain information about various basketball teams:

We can use the following formula to perform a left join on the two tables and return one table that contains the team name, points, and assists for every team in the left table:

=ArrayFormula(
   {
     A2:B6,
     vlookup(A2:A6,D2:E6,COLUMN(Indirect("R1C2:R1C"&COLUMNS(D2:E6),0)),0)
   }
)

The following screenshot shows how to use this formula in practice:

Google Sheets query join

Notice that the result is one table that contains the team name, points, and assists for every team in the left table.

Note: If a team in the left table does not exist in the right table, a value of #N/A will be returned in the Assists column of the resulting table.

The following tutorials explain how to perform other common tasks in Google Sheets

Google Sheets Query: How to Use Group By

x