# Merging 2 csv LEFT JOIN

**URL:** <https://discourse.nodered.org/t/merging-2-csv-left-join/46663>\
**Category:** General\
**Created:** [3 June 2021 18:49 UTC](https://discourse.nodered.org/t/merging-2-csv-left-join/46663 "2021-06-03T18:49:31Z")\
**Posts on this page:** 1\
**Showing post:** 11

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [4 June 2021 16:37 UTC](https://discourse.nodered.org/t/merging-2-csv-left-join/46663/11 "2021-06-04T16:37:33Z")

</div>

If the csvs are not same items then search for matching keys  
e.g.

```auto
$map(csv1, function($v,$i){
$merge([$v, $$.payload[Item = $v.Item]])
})

```

here is testing flow, as i have no files i created cvs's with template nodes.

```auto
[{"id":"bdbf843d.9a2268","type":"inject","z":"c74669a0.6a34f8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":110,"y":4020,"wires":[["e4bc4684.bce58"]]},{"id":"e4bc4684.bce58","type":"template","z":"c74669a0.6a34f8","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"Item;number1\nA;1\nB;2\nC;1\nD;3","output":"str","x":150,"y":4080,"wires":[["8e632ff3.bd8538"]]},{"id":"8e632ff3.bd8538","type":"csv","z":"c74669a0.6a34f8","name":"","sep":";","hdrin":true,"hdrout":"none","multi":"mult","ret":"\\n","temp":"","skip":"0","strings":true,"include_empty_strings":"","include_null_values":"","x":290,"y":4080,"wires":[["521fcad8.08ee6c"]]},{"id":"521fcad8.08ee6c","type":"change","z":"c74669a0.6a34f8","name":"","rules":[{"t":"set","p":"csv1","pt":"msg","to":"payload","tot":"msg"},{"t":"delete","p":"columns","pt":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":470,"y":4060,"wires":[["84e5cd7c.38bb2"]]},{"id":"84e5cd7c.38bb2","type":"template","z":"c74669a0.6a34f8","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"Item;number2\nA;4\nB;6\nD;8","output":"str","x":150,"y":4120,"wires":[["252c9dc1.b8e952"]]},{"id":"252c9dc1.b8e952","type":"csv","z":"c74669a0.6a34f8","name":"","sep":";","hdrin":true,"hdrout":"none","multi":"mult","ret":"\\n","temp":"","skip":"0","strings":true,"include_empty_strings":"","include_null_values":"","x":310,"y":4120,"wires":[["4fe5e194.63325"]]},{"id":"4fe5e194.63325","type":"change","z":"c74669a0.6a34f8","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"$map(csv1, function($v,$i){\t$merge([$v, $$.payload[Item = $v.Item]])\t})\t","tot":"jsonata"},{"t":"delete","p":"columns","pt":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":490,"y":4120,"wires":[["cd4b20af.9f15c8"]]},{"id":"cd4b20af.9f15c8","type":"csv","z":"c74669a0.6a34f8","name":"","sep":";","hdrin":"","hdrout":"all","multi":"mult","ret":"\\n","temp":"","skip":"0","strings":true,"include_empty_strings":"","include_null_values":"","x":730,"y":4120,"wires":[["ed65e41a.ce54a"]]},{"id":"ed65e41a.ce54a","type":"debug","z":"c74669a0.6a34f8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":680,"y":4020,"wires":[]}]

```

and if you want it dynamic that joins on first column then

```auto
$map(csv1, function($v,$i){
$merge([$v, $$.payload[$.*[0] = $v.*[0] ]])
})

```

---

_[View the full topic](https://discourse.nodered.org/t/merging-2-csv-left-join/46663)._
