# Join data sets

## Reference Entities in Read-operation

Initially look what are predefined reference entities linked to main entity. &#x20;

<figure><img src="https://3323790987-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FJyIxKYxK0LMJ2T3XubCS%2Fuploads%2FaAdL1EhSZmKqt7wY5jJB%2FJoin.png?alt=media&#x26;token=d39fb4f1-8e8a-48d9-814c-041271e57fef" alt=""><figcaption><p>Get UnitCode details of entity ParrCatalog</p></figcaption></figure>

## Reference entity not included in Entity?

* Do multiple requests and join with Flow script (shown below) or
* Is it possible to add reference to Entity using [IFS Entity Configuration](https://docs.novacura.com/flow-ifs-cloud-development-guidelines/flow-development-with-odata/configuration/configuring-projections-in-ifs/custom-projections) feature or
* create a [Custom Entity](https://docs.novacura.com/flow-ifs-cloud-development-guidelines/flow-development-with-odata/configuration/configuring-projections-in-ifs/custom-entities) as a new Projection in IFS and if it is possible to add the needed reference entities or
* explore possibilities provided by [Quick Reports](https://docs.novacura.com/flow-ifs-cloud-development-guidelines/flow-development-with-odata/configuration/configuring-projections-in-ifs/quick-reports) or [Query Builder](https://docs.novacura.com/flow-ifs-cloud-development-guidelines/flow-development-with-odata/configuration/configuring-projections-in-ifs/wip-query-designer) to build new custom projections.

## Join Entity Sets in flow

{% hint style="warning" %}
In Flow 6.15 a Flowscript Join function was introduced. Use this instead of the loop in the code example.
{% endhint %}

If several requests are necessary to get the data for the dataset, Flow script can be used to to join data into single Flow table.&#x20;

Example script to join previously read Customer and CustomerAddress entitysets.

The script works on any OData machine step output data structure, you just need to replace the key values in the script.&#x20;

```
customers = outCustomer.Results;
let addresses = outRefCustomerAddresses.Results;
let customerRecEmpty = Empty(outCustomer.Results).FirstOrEmpty();
let adddressTabEmpty = Empty(addresses);
let outTab = empty(*[customer: customerRecEmpty, addresses: adddressTabEmpty]);

for customer in customers {
 let addressesTempTab = addresses where CustomerId = customer.CustomerId;
 set outTab = outTab & [customer: customer, addresses: addressesTempTab];
 set addresses = addresses except where CustomerId = customer.CustomerId;  
 }
```
