> For the complete documentation index, see [llms.txt](https://docs.n8n.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.n8n.io/build/flow-logic/merge-data.md).

# Merge data

Merging brings multiple data streams together. You can achieve this using different nodes depending on your workflow requirements.

* Merge data from different data streams or nodes: Use the [Merge](/integrations/builtin/core-nodes/n8n-nodes-base.merge.md) node to combine data from various sources into one.
* Merge data from multiple node executions: Use the [Code](/integrations/builtin/core-nodes/n8n-nodes-base.code.md) node for complex scenarios where you need to merge data from multiple executions of a node or multiple nodes.
* Compare and merge data: Use the [Compare Datasets](/integrations/builtin/core-nodes/n8n-nodes-base.comparedatasets.md) node to compare, merge, and output data streams based on the comparison.

Explore each method in more detail in the sections below.

## Merge data from different data streams <a href="#merge-data-from-different-data-streams" id="merge-data-from-different-data-streams"></a>

If your workflow [splits](/build/flow-logic/split-with-conditionals.md), you combine the separate streams back into one stream.

Here's an [example workflow](https://n8n.io/workflows/1747-joining-different-datasets/) showing different types of merging: appending data sets, keeping only new items, and keeping only existing items. The [Merge node](/integrations/builtin/core-nodes/n8n-nodes-base.merge.md) documentation contains details on each of the merge operations.

{% @n8n-blocks/n8n-workflow-demo content="" url="<https://api.n8n.io/workflows/templates/1747>" %}

## Merge data from different nodes <a href="#merge-data-from-different-nodes" id="merge-data-from-different-nodes"></a>

You can use the Merge node to combine data from two previous nodes, even if the workflow hasn't split into separate data streams. This can be useful if you want to generate a single dataset from the data generated by multiple nodes.

<figure><img src="/files/9BsWPSDgOu761D1XJl2n" alt=""><figcaption><p>Merging data from two previous nodes</p></figcaption></figure>

## Merge data from multiple node executions <a href="#merge-data-from-multiple-node-executions" id="merge-data-from-multiple-node-executions"></a>

Use the Code node to merge data from multiple node executions. This is useful in some [Looping](/build/flow-logic/loop.md) scenarios.

{% hint style="info" %}
**Node executions and workflow executions**

This section describes merging data from multiple node executions. This is when a node executes multiple times during a single workflow execution.
{% endhint %}

Refer to this [example workflow](https://n8n.io/workflows/1814-merge-multiple-runs-into-one/) using Loop Over Items and Wait to artificially create multiple executions.

{% @n8n-blocks/n8n-workflow-demo content="" url="<https://api.n8n.io/workflows/templates/1814>" %}

## Compare, merge, and split again <a href="#compare-merge-and-split-again" id="compare-merge-and-split-again"></a>

The [Compare Datasets](/integrations/builtin/core-nodes/n8n-nodes-base.comparedatasets.md) node compares data streams before merging them. It outputs up to four different data streams.

Refer to this [example workflow](https://n8n.io/workflows/1943-comparing-data-with-the-compare-datasets-node/) for an example.

{% @n8n-blocks/n8n-workflow-demo content="" url="<https://api.n8n.io/workflows/templates/1943>" %}
