> 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>" %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.n8n.io/build/flow-logic/merge-data.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
