# Join data

Coupler.io allows you to fetch data from several sources at the same time, and join them into a unified dataset - all with a single importer.

Data **JOIN** is a term Coupler.io uses to describe the process of combining two or more sources using LEFT JOIN (from SQL terminology) - meaning, all the elements from the left set are kept while only matching elements from the right set are included

{% embed url="<https://www.youtube.com/watch?v=ZOi7mzr0e3c>" %}

### How to join data from multiple sources? <a href="#how-to-join-data-from-multiple-sources-7yscp" id="how-to-join-data-from-multiple-sources-7yscp"></a>

Let's take this example to understand this feature further. We have these source tables:&#x20;

{% columns %}
{% column width="58.333333333333336%" %}
*Source 1: Contacts*

<figure><img src="https://2487187314-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FCgnmco7kCnvytNIN8YdT%2Fuploads%2F45cJx6SrHvb8UEMuSVNv%2Fimage.png?alt=media&#x26;token=4f4fe20d-a01a-46fd-8284-933a5872f06f" alt="" width="563"><figcaption><p><em>Contacts</em></p></figcaption></figure>
{% endcolumn %}

{% column width="41.666666666666664%" %}
*Source 2: Department*

<figure><img src="https://2487187314-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FCgnmco7kCnvytNIN8YdT%2Fuploads%2FRcAdlSTEoaj9aQ3j4d6Q%2Fimage.png?alt=media&#x26;token=541c5cab-b05e-4c1e-9ef7-f505a277b814" alt="" width="369"><figcaption><p><em>Department</em></p></figcaption></figure>
{% endcolumn %}
{% endcolumns %}

**Goal**: We want to get a list of "Contacts" under the "Partner sales" department. Currently, the "Contacts" table only has the IDs.

{% @arcade/embed flowId="l8nSlkOARJd5A6WlsqIz" url="<https://app.arcade.software/share/l8nSlkOARJd5A6WlsqIz>" %}

{% stepper %}
{% step %}
After adding the needed sources, go to the "Transformations" step and either select Join data from the data preview window, or hit + Add transformation >> Create Join option from the left sidebar
{% endstep %}

{% step %}
Select the sources to join and the columns that will be used as the key:
{% endstep %}

{% step %}
Click the "Join data" button and we will get the following results:
{% endstep %}

{% step %}
After joining the data, you can apply [other transformations](https://docs.coupler.io/functionality/data-set/preview-data-and-data-sets) such as: hide and reorder columns, filter and sort data, add a formula column, etc. to achieve the desired result:
{% endstep %}
{% endstepper %}

#### 1. Order of key source matters <a href="#key-order" id="key-order"></a>

Let's review 2 sources

{% columns %}
{% column width="58.333333333333336%" %}
*Source 1: Users data*

<figure><img src="https://2487187314-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FCgnmco7kCnvytNIN8YdT%2Fuploads%2FrzTc9kIIbLOAWypVVvGL%2Fimage.png?alt=media&#x26;token=d6f50666-0dc5-4500-a5c5-fb1200ef1bd3" alt="" width="375"><figcaption><p>Users data</p></figcaption></figure>
{% endcolumn %}

{% column width="41.666666666666664%" %}
*Source 2: Additional user data*

<figure><img src="https://2487187314-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FCgnmco7kCnvytNIN8YdT%2Fuploads%2F7bFeOi9MsrSynXnY16M7%2Fimage.png?alt=media&#x26;token=0244601e-6de0-4bf1-a126-bcb38c4e4ce7" alt=""><figcaption><p>Additional user data</p></figcaption></figure>
{% endcolumn %}
{% endcolumns %}

As we can see, both of the tables contain "Id" column representing the user id. But, together with that, amount of rows is different: 10 and 3 respectively

* In case "Users data" is chosen as the Key source, we will receive the next result (10 rows as in the key source):

<figure><img src="https://2487187314-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FCgnmco7kCnvytNIN8YdT%2Fuploads%2F7pVIfE5MmmzQjiL7LZIt%2Fimage.png?alt=media&#x26;token=a0bcf88a-73c7-47c3-b35c-1beba834855c" alt=""><figcaption></figcaption></figure>

* In case "Additional user data" is chosen as the Key source, we will receive the next result (3 rows as in the key source):

<figure><img src="https://2487187314-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FCgnmco7kCnvytNIN8YdT%2Fuploads%2FrtLn35xylupgkCNA7Y1M%2Fimage.png?alt=media&#x26;token=66de1bc0-4354-4710-a10c-cf0291551497" alt=""><figcaption></figcaption></figure>

#### 2. Join by multiple fields <a href="#join-by-multiple-fields" id="join-by-multiple-fields"></a>

Along with Join by 2 sources, it is possible to join these sources by multiple fields

{% columns %}
{% column width="58.333333333333336%" %}
*Source 1: Users data*

<figure><img src="https://2487187314-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FCgnmco7kCnvytNIN8YdT%2Fuploads%2FZKAxQBNLzqOS0Cej1kiT%2Fimage.png?alt=media&#x26;token=336cc45b-b99e-4d73-82f6-a20ed00bdcb9" alt=""><figcaption><p>Users data</p></figcaption></figure>
{% endcolumn %}

{% column width="41.666666666666664%" %}
*Source 2: Additional user data*

<figure><img src="https://2487187314-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FCgnmco7kCnvytNIN8YdT%2Fuploads%2Fc0iLS0A8LvwJs4UrZGPX%2Fimage.png?alt=media&#x26;token=0de1c1d9-6a75-4572-a010-f014a2dfa652" alt=""><figcaption><p>Additional user data</p></figcaption></figure>
{% endcolumn %}
{% endcolumns %}

First, let's join these 2 sources by the "Id" field. The result will look like this (part of the data from "Additional user data" was cut due to missing references in the key source):

<figure><img src="https://2487187314-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FCgnmco7kCnvytNIN8YdT%2Fuploads%2FRzyqhNp8d8rTlWeG3wrB%2Fimage.png?alt=media&#x26;token=15f6dcb1-09de-47fd-acbb-c38638148583" alt=""><figcaption></figcaption></figure>

Next, we can join these 2 sources by one more column "Name".&#x20;

<div align="left"><figure><img src="https://2487187314-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FCgnmco7kCnvytNIN8YdT%2Fuploads%2FpWkxdujas61FL20v6f5K%2Fimage.png?alt=media&#x26;token=06982d3d-d2fa-45e7-a718-aed6c7fd93d6" alt="" width="375"><figcaption></figcaption></figure></div>

The result of both joins will look like this (first column changed):

<figure><img src="https://2487187314-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FCgnmco7kCnvytNIN8YdT%2Fuploads%2Fd0Y8J3cMGyMc5RTD1rU8%2Fimage.png?alt=media&#x26;token=e38bca73-a172-4102-a587-ce6af979db90" alt=""><figcaption></figcaption></figure>

As a next step, we can clean up (filter out) results a bit and leave only rows that contain data. Also, we can hide some columns to have no duplicates.

<div align="left"><figure><img src="https://2487187314-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FCgnmco7kCnvytNIN8YdT%2Fuploads%2F4Bo5ud66yacuDTO4ipo2%2Fimage.png?alt=media&#x26;token=8052845b-079f-41ef-9581-00b85b8db7d6" alt="" width="375"><figcaption></figcaption></figure></div>

And receive beautified results:

<figure><img src="https://2487187314-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FCgnmco7kCnvytNIN8YdT%2Fuploads%2Fuyq03GyYRBGI0tIyXEFB%2Fimage.png?alt=media&#x26;token=de0be110-e8fe-4483-9079-0314d35b0a5c" alt=""><figcaption></figcaption></figure>

#### 3. Join by multiple sources <a href="#join-by-multiple-sources" id="join-by-multiple-sources"></a>

**Goal:** We wanted to get a list of user names from the "Users" table, the amount of sold products from the "Transaction data" table, and product categories from the "Product data" table.

{% columns %}
{% column %}
*Source 1: Users data*

<figure><img src="https://2487187314-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FCgnmco7kCnvytNIN8YdT%2Fuploads%2F2QsR8tuWjn6JTZqqZV6x%2Fimage.png?alt=media&#x26;token=5f902638-8ad9-4c82-8d6e-edafffd3c9cf" alt=""><figcaption><p>Users Data</p></figcaption></figure>
{% endcolumn %}

{% column %}
*Source 2: Transaction data*

<figure><img src="https://2487187314-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FCgnmco7kCnvytNIN8YdT%2Fuploads%2FGb8X7B32rY7gU8xx410Z%2Fimage.png?alt=media&#x26;token=81a21f6a-7272-4af5-96e2-4551251d6208" alt=""><figcaption><p><em>Transaction data</em></p></figcaption></figure>
{% endcolumn %}

{% column %}
*Source 3: Product data*

<figure><img src="https://2487187314-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FCgnmco7kCnvytNIN8YdT%2Fuploads%2F0h8KRLqZDaNVGi0mYf0C%2Fimage.png?alt=media&#x26;token=37578c94-bb57-45c2-8ba4-fd252969f3ba" alt=""><figcaption><p><em>Product data</em></p></figcaption></figure>
{% endcolumn %}
{% endcolumns %}

Next data join setup will produce the desired result:

<div align="left"><figure><img src="https://2487187314-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FCgnmco7kCnvytNIN8YdT%2Fuploads%2F0JMzLyBMfViaal2Y3sAh%2Fimage.png?alt=media&#x26;token=2c00f183-cc26-4915-a160-e634dfd10f1d" alt="" width="375"><figcaption></figcaption></figure></div>

After applying data join along with the current transformation capabilities, the goal was achieved:

<div align="left"><figure><img src="https://2487187314-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FCgnmco7kCnvytNIN8YdT%2Fuploads%2Fxiu7o1PG7jziw0NSdMZ1%2Fimage.png?alt=media&#x26;token=0964bc82-23eb-4773-9e68-3aaf53966f4f" alt="" width="375"><figcaption></figcaption></figure></div>
