Merge Node Examples: Data Aggregation & Joins

Merge Node Examples: Data Aggregation & Joins

High-Level Summary

This workflow is an interactive tutorial that demonstrates the most common and powerful operations of n8n's Merge node. It shows how to combine data from two different sources using operations similar to SQL joins (Inner Join, Left Join, and Union All). Using simple, relatable examples like recipe ingredients and rock band members, this workflow visually explains how to filter, enrich, and merge datasets. It is designed as a learning tool for users who want to understand data aggregation patterns in n8n without needing external services or credentials.

Step-by-Step Node Breakdown

1. On clicking 'execute' (Manual Trigger) — No auth

  • Type: n8n-nodes-base.manualTrigger
  • Parameters: None (no configuration needed)
  • Purpose: Starts the workflow when the user clicks the "Execute Workflow" button in the n8n editor. This is a manual trigger, ideal for testing and learning.

2. A. Ingredients Needed (Code) — No auth

  • Type: n8n-nodes-base.code
  • Parameters: Returns a static array of 5 ingredient objects: Flour, Eggs, Milk, Lemon, Sugar.
  • Purpose: Simulates a list of ingredients required for a recipe (Dataset A).

3. B. Ingredients in stock (Code) — No auth

  • Type: n8n-nodes-base.code
  • Parameters: Returns a static array of 3 ingredient objects: Eggs, Lemon, Sugar.
  • Purpose: Simulates a list of ingredients currently available in stock (Dataset B).

4. Ingredients in stock from recipe (Merge) — No auth

  • Type: n8n-nodes-base.merge
  • Parameters:
    • mode: combine (Merge mode)
    • mergeByFields: Matches on Name field from both inputs
    • options: None (default behavior)
  • Purpose: Performs an Inner Join — keeps only ingredients from Dataset A (Ingredients Needed) that also exist in Dataset B (Ingredients in stock). Output: Eggs, Lemon, Sugar.

5. A. Ingredients (Code) — No auth

  • Type: n8n-nodes-base.code
  • Parameters: Returns the same static array as node 2 (5 ingredients).
  • Purpose: Provides Dataset A for the enrichment example.

6. B. Recipe quantities (Code) — No auth

  • Type: n8n-nodes-base.code
  • Parameters: Returns a static array of 5 ingredient objects with Name and Quantity fields (e.g., Flour: 100g, Eggs: 2, Salt: 50g, Lemon: 1, Sugar: 6tbsp).
  • Purpose: Simulates a dataset with additional quantity information (Dataset B).

7. Merge recipe (Merge) — No auth

  • Type: n8n-nodes-base.merge
  • Parameters:
    • mode: combine
    • joinMode: enrichInput1 (Left Join)
    • mergeByFields: Matches on Name field from both inputs
  • Purpose: Performs a Left Join — keeps all items from Dataset A (Ingredients) and enriches them with matching data from Dataset B (Recipe quantities). For example, Flour gets Quantity: 100g, while Milk (no match in B) gets no quantity.

8. A. Queen (Code) — No auth

  • Type: n8n-nodes-base.code
  • Parameters: Returns a static array of 4 objects representing Queen band members (e.g., Freddy Mercury, Brian May).
  • Purpose: Provides Dataset A for the Union All example.

9. B. Led Zeppelin (Code) — No auth

  • Type: n8n-nodes-base.code
  • Parameters: Returns a static array of 4 objects representing Led Zeppelin band members (e.g., Jimmy Page, Robert Plant).
  • Purpose: Provides Dataset B for the Union All example.

10. Super Band (Merge) — No auth

  • Type: n8n-nodes-base.merge
  • Parameters:
    • mode: combine (default, no join mode specified)
    • No merge fields configured
  • Purpose: Performs a Union All — combines all items from both datasets into a single list. The result is a "super band" with 8 members (Queen + Led Zeppelin). Unlike SQL Union All, this does not require identical field structures.

11. Note / Note1 / Note2 / Note4 / Note6 / Note8 / Note9 (Sticky Notes) — No auth

  • Type: n8n-nodes-base.stickyNote
  • Parameters: Each contains explanatory text describing the purpose of adjacent merge operations.
  • Purpose: Provide inline documentation and visual guidance within the workflow canvas.

Setup Instructions

This workflow requires no external services, accounts, or credentials. It is entirely self-contained using static data generated by Code nodes. To use it:

  1. Import the workflow into your n8n instance (version 0.200.0 or later recommended).
  2. Click the "Execute Workflow" button to run all branches simultaneously.
  3. Double-click on any Merge node to inspect its input and output data.
  4. Read the sticky notes for explanations of each merge operation.

No API keys, database connections, or third-party accounts are needed.

Use Cases and Variations

This workflow is primarily an educational template for understanding data merging patterns. You can adapt it to real-world scenarios:

  • Inner Join (Ingredients in stock): Use when you need to filter records that exist in both datasets — e.g., matching customer emails from two lists, or finding products that are both in a catalog and in stock.
  • Left Join / Enrichment (Merge recipe): Use when you have a primary dataset and want to add supplementary information from another source — e.g., enriching user profiles with purchase history, or adding product prices to an order list.
  • Union All (Super Band): Use when you need to combine two or more datasets with different structures into a single list — e.g., merging leads from multiple marketing channels, or consolidating reports from different departments.

To adapt this workflow:

  • Replace Code nodes with real data sources (HTTP Request, Database, Google Sheets, etc.)
  • Change merge fields to match your actual data schema
  • Add output nodes (e.g., Send Email, Write to Database, Create File) to act on the merged results
  • Schedule the workflow using a Cron or Schedule trigger for recurring data processing tasks
17 nodesmanual triggerData
Sticky NoteMergeCode

Workflow JSON

{
  "meta": {
    "instanceId": "8c8c5237b8e37b006a7adce87f4369350c58e41f3ca9de16196d3197f69eabcd"
  },
  "nodes": [
    {
      "id": "9971f7ab-ecc3-468b-8eb9-b58491b660bd",
      "name": "On clicking 'execute'",
      "type": "n8n-nodes-base.manualTrigger",
      "position": [
        1040,
        360
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "bb212963-9b6f-434c-9777-3360fb456d4b",
      "name": "Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1320,
        600
      ],
      "parameters": {
        "width": 1020,
        "height": 360,
        "content": "# 3. Add items from B below items from A\n"
      },
      "typeVersion": 1
    },
    {
      "id": "cc9461f1-1016-4ef5-bc10-525942c45047",
      "name": "Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1320,
        -200
      ],
      "parameters": {
        "width": 1020,
        "height": 380,
        "content": "# 1. Keep items from A if there's a match in B\n"
      },
      "typeVersion": 1
    },
    {
      "id": "09a68f64-5b2d-43a8-acff-7c26817cc025",
      "name": "Note2",
      "type": "n8n-nodes-base.stickyNote",
// ... truncated (copy to see full JSON)

How to Import This Workflow

  1. 1Copy the workflow JSON above using the Copy Workflow JSON button.
  2. 2Open your n8n instance and go to Workflows.
  3. 3Click Import from JSON and paste the copied workflow.

Don't have an n8n instance? Start your free trial at n8nautomation.cloud

Related Templates

AI-Powered CV Scanner with Google Sheets & Gemini

Overview This workflow automates the initial screening of job applicants by combining a web form, AI-powered CV analysis, and Google Sheets. When a candidate submits their application (name, email, and CV PDF), the workflow instantly extracts the text from the PDF using Mistral OCR, then sends it to Google Gemini for evaluation against a predefined job description. The AI returns a qualification score (0.0 to 1.0) and a detailed explanation, which are then logged alongside the candidate's details in a Google Sheet. This eliminates manual CV review, speeds up your hiring pipeline, and ensures every applicant is evaluated consistently. Workflow Steps Application Form (Form Trigger) — No auth required. This node presents a custom-branded web form to collect the candidate's Full Name, Email, and CV (PDF upload). The form is styled with a dark, glassmorphism theme and includes animated backgrounds. Once submitted, the workflow triggers automatically. Log Candidate Submission (Google Sheets) — OAuth2. Immediately after form submission, this node appends the candidate's name and email to the 'CVs' Google Sheet. This ensures the application is recorded even if the subsequent analysis steps fail. Extract CV Text (Mistral AI) — API Key auth. This node takes the uploaded PDF file from the form and uses Mistral's OCR API to extract all text content from the CV. It dynamically selects the binary file uploaded in the previous step. AI Qualification (LLM Chain) — This is the core analysis node. It uses a detailed prompt that includes: - A system message defining the AI as a professional, objective hiring assistant. - The full job description for a "Senior Frontend Developer" with core requirements and preferred qualifications. - Clear evaluation logic: candidates missing core requirements cannot score above 0.6; meeting all core requirements yields at least 0.75; preferred qualifications add bonuses up to 1.0. - The extracted CV text as context. - An instruction to output raw JSON only. Gemini 2.5 Flash Lite (Language Model) — API Key auth (Google AI Studio). This node provides the actual AI model (Google Gemini 2.5 Flash Lite) with a temperature of 0.4 for balanced, deterministic outputs. It powers the LLM Chain above. JSON Output Parser (Output Parser) — This node ensures the AI's response is valid JSON with the exact schema: (number) and (string). It prevents malformed responses from breaking downstream nodes. Add CV Analysis (Google Sheets) — OAuth2. After analysis, this node updates the candidate's row in the 'CVs' sheet by matching on the Email column. It writes the and from the AI's output into the corresponding columns. Create 'CVs' Spreadsheet (Google Sheets) — OAuth2. This node runs once when the workflow is first triggered manually. It creates a new Google Sheet named 'CVs' with columns: FullName, Email, QualificationRate, QualificationDescription. Setup Instructions Prerequisites A Google account (for Google Sheets) A Mistral AI account (free tier available) — Get your API key here A Google AI Studio account — Create an API key here Step-by-Step Google Sheets Credentials: In the three Google Sheets nodes, create or select an OAuth2 credential for Google Sheets. Grant access to create and edit spreadsheets. Mistral AI Credential: In the "Extract CV Text" node, create a new credential and paste your Mistral API key. Gemini Credential: In the "Gemini 2.5 Flash Lite" node, create a new credential and paste your Google AI Studio API key. Customize Job Description: Open the "AI Qualification" node and edit the section in the prompt to match your actual job posting. Activate the Workflow: Toggle the workflow to "Active" status. The "Application Form" node will generate a public URL you can share with candidates. Test: Use the "Start Here" manual trigger to initialize the Google Sheet, then submit a test application via the form URL. Use Cases & Variations Custom Job Roles: Replace the Senior Frontend Developer description with any role (e.g., Marketing Manager, Data Scientist, Sales Rep) by editing the prompt in the AI Qualification node. Different Storage: Replace Google Sheets with Airtable, Notion, or a database like PostgreSQL for storing applications and results. Multi-Round Screening: Add a Slack or email notification node to alert the hiring team when a candidate scores above a certain threshold (e.g., >0.8). Interview Scheduling: Connect the output to a Calendly or Google Calendar node to automatically invite high-scoring candidates for an interview. Batch Processing: Modify the trigger to accept a CSV upload of multiple CVs for bulk analysis. Enhanced Analysis: Add more output fields like "years of experience", "top skills", or "red flags" by updating the JSON schema in the Output Parser and the prompt.

18 nodes

Talk to Your Google Sheets Data Using OpenAI Chat Agent

This workflow transforms a Google Sheet into a live, conversational database. Using an AI agent powered by OpenAI's GPT-4.1-nano model, you can ask natural language questions about your spreadsheet data and receive accurate, context-aware answers — without writing any SQL or formulas. The agent can handle queries like total campaign spend, per-channel breakdowns, month-over-month trends, and cost-per-lead calculations. Workflow Steps Node-by-Node Breakdown Chat with Your Data (Chat Trigger) — This is the entry point of the workflow. It provides a chat interface (webhook) where users type their questions. No authentication is required to trigger the webhook; access can be secured at the workflow level. Memory (Buffer Window Memory) — Stores recent conversation history so the AI can reference previous exchanges. The buffer window keeps the last few messages to maintain context without excessive token use. No authentication required. OpenAI Chat Model (OpenAI GPT-4.1-nano) — The language model that processes user questions and generates answers. Uses API Key auth (you must provide an OpenAI API key). Parameters: model = , no additional options configured. Talk to Your Data (AI Agent) — The core agent that orchestrates the conversation. It receives user input, decides which tool to call (only the Google Sheets tool is available), and returns answers. Uses API Key auth (uses the same OpenAI credential as the model). Parameters include a system message: "Google Sheets Ask-… You are Ask-… Answer questions using Google Sheets ONLY via the tool below. Be precise and conservative. There is only one dataset. Don't ask what dataset it is. Use the data tool to answer the question." Analyze Data (Google Sheets Tool) — The tool the agent calls to read spreadsheet data. Uses OAuth2 authentication (Google Sheets). Parameters: document ID = ("Sample Marketing Data - n8n"), sheet name = "Data" (gid: 365710158). No additional options set. Sticky Notes (Information Only) — Provide setup instructions and tips. Not executable nodes. Setup Instructions Before using this workflow, you need: OpenAI Account — Visit OpenAI API Keys to generate an API key. Make sure you have billing set up at OpenAI Billing and have credits available. Google Account — You need access to a Google Sheet. The sample uses a specific sheet, but you can point it to any sheet with a similar structure: first row = column headers, rows 2–100 = data. To configure: In the OpenAI Chat Model node, create an OpenAI credential with your API key. In the Analyze Data node, create a Google Sheets OAuth2 credential (select your Google account and authorize access). Update the Document ID and Sheet Name to match your own Google Sheet. Optionally update the system message in the Talk to Your Data agent if you want to change the assistant's personality or instructions. Use Cases and Variations This workflow is perfect for: Marketing teams wanting instant answers about campaign performance, spend, and ROI. Sales operations analyzing pipeline data, deal stages, or conversion metrics. Small business owners asking questions about inventory, sales, or customer data without learning SQL. Adaptations: Replace Google Sheets with another data source tool (e.g., Airtable, Notion, PostgreSQL, MySQL) by swapping the "Analyze Data" node. Add more tools to the agent (e.g., a web search tool, a calculator) to expand its capabilities. Change the model to GPT-4o or GPT-3.5-turbo for faster/cheaper responses. Add a Slack or Webhook trigger instead of the chat trigger for a different user interface.

11 nodes

Extract company website metadata via Apify Company Enrichment

This workflow takes a single company domain (e.g., ), validates it, runs it through Apify's Company Enrichment actor, and returns a verified metadata result with provenance. It is designed as a building block for CRM enrichment, lead generation, or data quality pipelines. Workflow Steps Run manually (Manual Trigger) – Starts the workflow on demand. No schedule is set; you can extend it with a cron trigger. Set company domain (Set node) – Hardcodes the domain into a field . Change this to your target domain. Validate domain (Code node, JavaScript) – Validates the domain format (length, allowed characters, no protocol or path). Throws an error if invalid. Also attaches an marker for downstream validation. Extract metadata on Apify (HTTP Request, Header Auth) – Sends a POST request to the Apify actor's sync endpoint with the domain payload. Uses Header Auth with a custom header . Parameters: , to cap cost. Timeout 150 seconds. Validate metadata result (Code node, JavaScript) – Checks the response: only one item, , domain matches, integration source matches, and provenance method is . Rejects any unexpected or empty results. Setup Instructions Get an Apify API token – Sign up or log in at apify.com. Create a token scoped to run actors (). Create an n8n Header Auth credential – In n8n, go to Credentials > New > Header Auth. Set the header name to and value to . Attach this credential to the Extract metadata on Apify node. Replace the default domain – In the Set company domain node, change to your target company domain (e.g., ). Review pricing – The actor charges per run. The workflow caps cost at $0.02 USD per call. Review actor pricing before scaling. Run manually – Click Execute Workflow to test. The output will be a single enriched company object. Use Cases & Adaptations CRM integration – Pipe the output into Salesforce or HubSpot via an HTTP Request or their respective n8n nodes. Bulk enrichment – Replace the manual trigger with a Schedule Trigger or a Spreadsheet File Trigger to process thousands of domains from a Google sheet or CSV. Data validation – Use the validated result to enrich lead lists, verify company websites, or update a database. Custom enrichment – Replace the Apify actor with another REST API (e.g, Clearbit, Zoominfo) by modifying the HTTP Request node and validation logic.

6 nodes

Ready to automate with n8n?

Get affordable managed n8n hosting with 24/7 support.