HomeGoogle DocsSpreadsheetHow to Full Join Two Tables in Google Sheets

How to Full Join Two Tables in Google Sheets

Published on

In this detailed walkthrough, you’ll learn how to successfully perform a full join on two tables in Google Sheets.

A full join combines all records (rows) from both tables, regardless of whether they have matching values in a common field (column). It requires the presence of a unique identifier column in each table.

Matching records occupy the same row, while unmatched records from either table are included with missing values for corresponding fields in the other table.

Before proceeding, make sure:

  1. Both tables should have a unique identifier column. This column must contain distinct values for each record in the right table. This represents the most common scenario when joining two tables.
  2. The data types of the identifier columns in both tables are compatible. For example, both should be text, or both should be numbers.

Now, we’ll explore sample tables, expected results, the formula, and an explanation for performing a full join in Google Sheets.

Note: If you have duplicated IDs in both ID columns (left and right tables), please check out this guide: Conquer Duplicate IDs: Master Left, Right, Inner, & Full Joins in Google Sheets.

Full Join Two Tables: Sample Tables and Resulting Table

Orders (Left Table):

Order IDCustomer IDItemPrice
A11001Shirt18.00
A21002Laptop650.00
A31004Headphones24.00
A41001T-Shirt15.00

Customers (Right Table):

Customer IDNameCity
1001JohnMumbai
1002MaryamCochin
1003OliviaBangalore

Expected Result of Full Join:

Customer IDOrder IDItemPriceNameCity
1001A1Shirt18.00JohnMumbai
1002A2Laptop650.00MaryamCochin
1004A3Headphones24.00
1001A4T-Shirt15.00JohnMumbai
1003OliviaBangalore

In this example, both tables share a common “Customer ID” column.

A full join combines all rows based on this shared identifier, including cases where some customers have no orders or some orders have no related customer information.

Array Formula for Full Joining Two Tables in Google Sheets

The following array formula performs a full join between two tables in Google Sheets. It assumes unique records in the right table.

Formula:

=ArrayFormula(
     LET(
          lt, A2:D6, lt_id, B2:B6, rt, F2:H5, rt_id, F2:F5, 
          key, VSTACK(lt_id, TOCOL(IFNA(XMATCH(rt_id, lt_id)/0, rt_id), 3)),
          look_up, IFNA(VLOOKUP(key, HSTACK(rt_id, rt), SEQUENCE(1, COLUMNS(rt)+1), 0), HSTACK(key, )), 
          IFNA(HSTACK(lt, look_up))
     )
)
Full Join Two Tables in Google Sheets (Example)

Where:

  • A2:D6 is the left table range, including the header row.
  • B2:B6 is the unique identifier column in the left table, including the field label.
  • F2:H5 is the right table range, including the header row.
  • F2:F5 is the unique identifier column in the right table, including the field label.

In the above formula, you need to replace IFNA(HSTACK(lt, look_up)) with CHOOSECOLS(IFNA(HSTACK(lt, look_up)), {5, 1, 3, 4, 7, 8}) to get a result similar to the resulting table above. This modification, specifically CHOOSECOLS, selects the required columns from the full join in the desired order.

Note: If any column in either of the two tables contains dates, you should format that column in the joined table as Format > Number > Date.

Check cell A11 of the fifth sheet in the provided sample sheet below for the full join array formula.

Sample Sheet

Formula Breakdown

To simplify the modification of the full join array formula, we’ve utilized the LET function.

The LET function assigns a name to a calculation result or a cell/range reference. This allows you to reuse those values within your formula without repeating the calculation or reference, improving both performance and readability.

Syntax of the LET Function:

LET(name1, value_expression1, [name2, …], [value_expression2, …], formula_expression)

Assigned Range References

Here are the range references for the full Joining of two tables in Google Sheets:

  • lt (name1): Defines the data range of the left table (Orders), including the header row.
    • A2:D6 (value_expression1): Data range of the left table (Orders).
  • lt_id (name2): Defines the ID column of the left table (Orders), including the header row.
    • B2:B6 (value_expression2): ID column of the left table (Orders).
  • rt (name3): Defines the data range of the right table (Customers), including the header row.
    • F2:H5 (value_expression3): Data range of the right table (Customers).
  • rt_id (name4): Defines the ID column of the right table (Customers), including the header row.
    • F2:F5 (value_expression4): ID column of the right table (Customers).

Note: You only need to specify the above value_expressions 1 to 4 for your two tables. The full join array formula will take care of the rest.

Assigned Intermediate Calculation Results

VLOOKUP Keys: Search Keys for Full Join

  • key (name5): Defines the search keys for VLOOKUP
    • VSTACK(lt_id, TOCOL(IFNA(XMATCH(rt_id, lt_id)/0, rt_id), 3)) (value_expression5):

This “key” serves as a crucial element for performing a full join in Google Sheets. It vertically combines two components:

  • All unique identifiers from the left table: This ensures all left table records are included in the join.
  • Unique identifiers from the right table that are missing in the left table: This is achieved through a combination of XMATCH, error conversion, and IFNA.
    • XMATCH locates and returns the index (position) of each right identifier within the left table. For unmatched values, it returns #N/A.
    • Dividing the position by zero intentionally triggers matching IDs to return DIV/0! values.
    • IFNA replaces #N/A values with the corresponding right identifiers.
    • Finally, TOCOL converts this list of right-only identifiers into a single column.

By stacking (VSTACK) this “right-only” column with the left table identifiers, the “key” ensures all rows from both tables are included in the full join based on their unique ID presence.

VLOOKUP: The Soul of Full Joining Two Tables in Google Sheets

VLOOKUP is a crucial component of the full join between two tables in Google Sheets.

  • look_up (name6):
    • IFNA(VLOOKUP(key, HSTACK(rt_id, rt), SEQUENCE(1, COLUMNS(rt)+1), 0), HSTACK(key, )) (value_expression6):

This part of the formula performs a lookup operation to retrieve data from the right table (rt) based on the key column created earlier. Let’s break it down step-by-step:

  1. VLOOKUP:
  • VLOOKUP(key, HSTACK(rt_id, rt), SEQUENCE(1, COLUMNS(rt)+1), 0) is the core lookup function.
    • key: This is the column containing the combined unique identifiers from both tables (created by VSTACK earlier).
    • HSTACK(rt_id, rt): This specifies the lookup range. This combines the right table identifier column (rt_id) with the right table (rt) horizontally.
    • SEQUENCE(1, COLUMNS(rt)+1): Generates a range of numbers representing the column positions in the right table.
    • 0: This indicates an exact match is required for the lookup.
  1. IFNA:
  • This function wraps the VLOOKUP to handle potential errors.
  • If a match is found for a key in the right table, VLOOKUP returns the corresponding data from the lookup range (HSTACK(rt_id, rt)).
  • If no match is found, VLOOKUP returns an array of #N/A errors, with the number of errors matching the size of the lookup range (number of columns).
  • IFNA replaces any potential errors with a pattern derived from HSTACK(key, ). This pattern replicates the key in the first cell and fills the remaining cells with NA values, matching the number of columns returned by VLOOKUP in the case of successful lookups.
The Role of VLOOKUP in Full Join Two Tables in Sheets

Full Join Formula_Expression Part

This segment merges the data from the left table (lt) with the lookup result (look_up) and replaces #N/A (returned during stacking) with blanks.

IFNA(HSTACK(lt, look_up))

Formula Breakdown:

  • HSTACK(lt, look_up): This part horizontally concatenates (stacks) the data from the left table (lt) with the lookup results (look_up) from the right table.
  • IFNA(HSTACK(lt, look_up)): This wraps the preceding step with the IFNA function. This function replaces any potential errors encountered during the lookup with blank values.

Important Notes:

The lookup result includes all records from the right table. This ensures a full join, even for records with no matching information in the left table.

Wrapping this formula in CHOOSECOLS is necessary when the full join creates multiple unique identifier columns. This function allows you to select specific columns from the joined result, including just the key column you created.

E.g.: CHOOSECOLS(IFNA(HSTACK(lt, look_up)), {5, 1, 3, 4, 7, 8})

Prashanth KV
Prashanth KV
Your Trusted Google Sheets and Excel Guide Prashanth KV brings a wealth of experience in Google Sheets and Excel, cultivated through years of work with multinational corporations in Mumbai and Dubai. As a recognized Google Product Expert in Docs Editors, Prashanth shares his expertise through insightful blogging since 2012. Explore his blog for practical tips and guidance on maximizing your spreadsheet skills.

Appointment Schedule Template in Google Sheets

An appointment schedule template in Google Sheets can assist you in efficiently managing your...

Creating Sequential Dates in Equally Merged Cells in Google Sheets

Do you know how to create sequential dates in equally merged cells across a...

Running Total By Month in Excel

This tutorial demonstrates how to calculate the running total by month in a range...

SORT and SORTBY – Excel Vs Google Sheets

While Excel offers the SORT and SORTBY functions for sorting a table, Google Sheets...

More like this

Appointment Schedule Template in Google Sheets

An appointment schedule template in Google Sheets can assist you in efficiently managing your...

Creating Sequential Dates in Equally Merged Cells in Google Sheets

Do you know how to create sequential dates in equally merged cells across a...

Interactive Random Task Assigner in Google Sheets

You have multiple tasks and multiple people. Here's a fun way to randomly assign...

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.