Iterating over array items with Split Out + Loop Over Items to run SQL queries and merge results into one object

Hi everyone,
I’m building a workflow in n8n where:

  1. I receive an array of keywords.
  2. I use a Split Out node to turn them into individual items.
    • Example of Split Out output:
[
  { "keywords": "aspirin" },
  { "keywords": "pain" },
  { "keywords": "fever" }
]
  1. I pass those items into a Loop Over Items node.
  2. Inside the loop, I want to run a SQL query (Supabase) for each keyword.
    • For example, using the filter:
description=ilike.%{{$json.keywords}}%
  1. Finally, I want to merge all results from each iteration into a single object/array so I can process them later, something like this:
{
  "results": [
    { "id": 1, "description": "Contains aspirin" },
    { "id": 2, "description": "Treatment for pain" },
    { "id": 3, "description": "Reduces fever" }
  ]
}

:red_question_mark: Current issue

  • Split Out works correctly and generates separate items.
  • Loop Over Items receives each keyword one by one.
  • The SQL node runs, but at the end I don’t know how to combine all results from the loop into one object.

:camera: Screenshots

(Here I would attach the screenshots: Split Out with keywords, Loop configuration, SQL node with filters, etc.)

:folded_hands: Question

What’s the best way in n8n to merge the SQL results from each iteration into a single object/array after the loop finishes?
Should I use a Function Node at the end, a Merge Node (Append), or is there a more straightforward way to do this in n8n?

At the end add Aggregate node to the “done” branch to pull all separate resulting items into a single list of items like this

1 Like

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