# Data Merging

* Merge data from multiple sources using the Merge node.
* Combine data from different node runs using the Code node for complex scenarios requiring data merging from various node executions.
* Compare and merge data: The `Compare Datasets` node is used to compare, merge, and output data streams.

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

When your workflow diverges, you must reintegrate the individual streams into a unified stream. An [illustrative workflow](https://n8n.io/workflows/1747-joining-different-datasets/?_gl=1*100r06d*_gcl_au*MTgyMDQ5NDMwMi4xNzE1MzQxMTgw*_ga*MTU2MDY2MzUyMC4xNzE5NDgzMzA4*_ga_0SC4FF2FH9*MTcyMTc5OTE1Ni4xMy4xLjE3MjE4MDAwMjAuNTguMC4w) is presented to demonstrate various forms of consolidation, such as concatenating data sets, retaining solely fresh entries, and preserving solely current entries.

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

You can merge data from two previous nodes using the Merge node. This is helpful for creating a single dataset from multiple nodes' data.

<figure><img src="https://125370873-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FzdpN2Lz0hzXpnNScDzVt%2Fuploads%2FWXbZgc7kk5Auoo11VjdR%2Fimage.png?alt=media&#x26;token=95ca0cf9-3fdb-451d-9f2f-c8d0334126ec" alt=""><figcaption></figcaption></figure>

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

Utilize the Code node to combine data from different node runs, especially in Looping situations.

This section explains combining data from multiple node runs, which occurs when a node runs multiple times within one workflow execution.

[Example workflow](https://n8n.io/workflows/1814-merge-multiple-runs-into-one/?_gl=1*tytjqb*_gcl_au*MTgyMDQ5NDMwMi4xNzE1MzQxMTgw*_ga*MTU2MDY2MzUyMC4xNzE5NDgzMzA4*_ga_0SC4FF2FH9*MTcyMTc5OTE1Ni4xMy4xLjE3MjE4MDAxODMuNTguMC4w) demonstrates using Loop Over Items and Wait to simulate multiple executions.

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

The Compare Datasets node checks data streams before combining them, producing four data streams as output.

[Refer sample here](https://n8n.io/workflows/1943-comparing-data-with-the-compare-datasets-node/?_gl=1*1b4si1z*_gcl_au*MTgyMDQ5NDMwMi4xNzE1MzQxMTgw*_ga*MTU2MDY2MzUyMC4xNzE5NDgzMzA4*_ga_0SC4FF2FH9*MTcyMTc5OTE1Ni4xMy4xLjE3MjE4MDAzMjEuNjAuMC4w)<br>
