How to concat/merge specific column from rows having the same key in n8n

I fetch data from a DB that stores a unique key for every client and along with their products.
Each key represents a session and each session can have multiple products like this:

  • 7856 Shirt
  • 7856 Trousers
  • 7856 Jacket
  • 9056 Scarf
  • 9056 Blouse

I would like to have an output that looks like this:

  • 7856 Shirt, Trousers, Jacket
  • 9056 Scarf, Blouse

I am a complete noob with code so if a nocode way is possible I’d prefer that. If not possible w/o code, that is fine as well.

Thank you.

n8n version: 0.182.0
Running n8n via desktop app

Hi @Watsonius, based on your description you’ll need at least expressions to make this work, but it should be fairly simple. Assuming values such as 7856 and Shirt appear in their own field, something like this would do the job:

This approach uses JMESPath for the filtering inside the Set node and produces a result like this:

Hope this helps!

You might need to upgrade your desktop app to the latest available version first before this example works. I’ve only tested it on the desktop app version currently available on Get started with n8n.

Thanks. I have not come across JMESPath before but it looks like it will work. Let me try it out and will let you know.
Thanks for including an example I can play around with to figure this out.

1 Like

It works!
Thank you so much.

2 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.