# Dataset Merge & Dedupe: Combine Datasets, Remove Duplicates (`subtleasianmerch/dataset-merge-dedupe`) Actor

Merge Apify datasets into one and remove duplicate rows, by key fields such as url or id, or by whole row when you give none. Keep the first or the last of each, pick and rename fields, and save to a named dataset. Rows read and duplicates are free.

- **URL**: https://apify.com/subtleasianmerch/dataset-merge-dedupe.md
- **Developed by:** [Public Data Tools](https://apify.com/subtleasianmerch) (community)
- **Features:** Limited permissions
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $0.10 / 1,000 row writtens

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.

Learn more: https://docs.apify.com/actors/running/actors-in-store.md#pay-per-event

## What's an Apify Actor?

An Actor is a serverless cloud program that runs on the Apify platform. It has two run modes.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.

Apify vocabulary and the platform model are defined once, in the agent quickstart at https://apify.com/agents.md.

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.

Do not guess an integration path. Every one of them is in the agent quickstart at https://apify.com/agents.md: the Apify MCP server, Agent Skills with the Apify CLI, the JavaScript and Python clients, the REST API, and the account-free path for an agent with no human to sign in. It also carries the rule on stating cost before the first paid run.

For examples already wired to this Actor's own input schema, see the [API](#api) section below.

Each client library has reference documentation the quickstart does not restate: [JavaScript/TypeScript](https://docs.apify.com/api/client/js/docs.md) (`npm install apify-client`) and [Python](https://docs.apify.com/api/client/python/docs.md) (`pip install apify-client`).

# README

## Dataset Merge & Dedupe: Combine Datasets, Remove Duplicates

Merge the results of several Apify runs into **one clean dataset without duplicate rows**. Compare rows by the fields that identify them, such as `url` or `id`, or by the whole row when you give none. Keep the first or the last of each duplicate, pick and rename fields, and save to a named dataset if you like.

- 🧩 **Merge any number of datasets**, plus rows you paste in as JSON, in the order you give them.
- 🔑 **Duplicates by key fields or by whole row:** `url`, `id`, `address.city`, or several fields together. With no fields, identical rows are removed.
- ⏮️ **Keep the first or the last** of each duplicate: the last one is the newest when your datasets are in date order.
- ✂️ **Pick, order and rename fields** without code: `address.city as city`.
- 🗂️ **Save to a named dataset** that keeps growing across runs, or to the run's own dataset.
- 🛑 **Clear errors:** a wrong dataset ID stops the run with a message saying which one, before anything is output or charged.
- 💸 **$0.10 per 1,000 output rows.** Rows read, duplicates and empty rows are free.

**Try it:** the input comes pre-filled with three rows, one of them a duplicate. Click **Start** and you get two rows back. Then pick your own datasets.

### What you get

One row per unique row of your data, with your own fields, in the order they first appear (or where the kept row appears, with **Keep: the last one**).

| Data | What's in it |
|---|---|
| **Your rows** | every field as it is, or only the fields you chose, in your order and with your names |
| **Run summary** (`RUN_SUMMARY`) | rows read and output, duplicates skipped, empty rows skipped, rows kept because they had no key value, each dataset with how many rows were read from it, and whether a limit stopped the run |

Hidden fields (names starting with `#`, such as Web Scraper's `#debug`) are left out, as in Apify's "clean" export, so they don't make identical rows look different.

### Who it's for

- **Anyone who scrapes in batches:** combine the results of many runs of the same scraper into one list without repeats.
- **Lead and job lists:** merge searches that overlap (several keywords or cities) and keep one row per company, profile or job ID.
- **Price and listing monitors:** keep only the newest row of each product with **Keep: the last one**.
- **Spreadsheet and CRM exports:** trim a dataset to the columns you need and give them readable names before you download it.

### How much does it cost?

You pay **$0.10 per 1,000 rows output** ($0.0001 each), plus Apify's standard run start fee.

| Example | Rows output | Cost |
|---|---|---|
| Two scraper runs of 5,000 rows each, 2,000 duplicates | 8,000 | $0.80 |
| 30 daily runs of 1,000 rows, 20,000 duplicates | 10,000 | $1.00 |

- **Free:** rows read, duplicates, empty rows and the summary row.
- **Spending limit:** if you set a maximum cost per run, the run stops cleanly when it is reached and keeps what it already output.
- **Max rows:** caps the rows output.

### How to use it

1. Under **Datasets**, pick the results of earlier runs, or paste dataset IDs. A run ID is not a dataset ID: open the run, then **Storage**, to find its dataset.
2. Under **Compare by fields**, enter the field(s) that identify a row, such as `url`. Leave it empty to remove only identical rows.
3. Choose **Keep: the first one** or **the last one**.
4. Optionally list **Output fields** to keep, and give a **Named dataset** to save to.
5. Click **Start**, then download the results as JSON, CSV, Excel and more.

### Example input

```json
{
    "datasetIds": ["aBcDeFgHiJkLmNoPq", "rStUvWxYz01234567"],
    "keyFields": ["url"],
    "keep": "last",
    "fields": ["url", "title", "price", "seller.name as seller"],
    "outputDataset": "products-latest"
}
```

### Example output

With the pre-filled input:

```json
[
    { "name": "Example Ltd", "url": "https://example.com", "city": "London" },
    { "name": "Sample Inc", "url": "https://example.org", "city": "Austin" }
]
```

The run summary for it:

```json
{
    "read": 3,
    "output": 2,
    "duplicatesSkipped": 1,
    "emptySkipped": 0,
    "keptWithoutKey": 0,
    "keyFields": [],
    "keep": "first",
    "datasets": [],
    "missingDatasets": [],
    "inlineRows": 3,
    "outputDataset": null,
    "charged": 2,
    "stoppedAtMaxRows": false,
    "stoppedAtSpendingLimit": false,
    "finishedAt": "2026-11-11T08:00:00.000Z"
}
```

#### How duplicates are found

- **Key fields:** two rows are duplicates when all key fields have the same values.
  - Values compare as trimmed text, so `42` and `"42"` match.
  - Nested fields use dots (`address.city`). A whole object or list compares by its full content.
- **Whole rows:** with no key fields, two rows are duplicates when every field matches, in any order. Nested objects count, so `{"a": {"b": 1}}` and `{"a": {"b": 2}}` differ.
- **Rows with no key value** (every key field missing or empty) are all kept, not merged into one. The summary counts them.
- **Empty rows** (`{}`) are skipped.

#### Keep the first or the last

- **Keep: the first one:** reads each dataset once.
- **Keep: the last one:** reads them twice. The first pass finds the last row of each key; the second outputs it.
  - Rows added to a dataset between the two passes (a scraper still running) are left out.
  - Merge finished runs for a complete result.

### Integrations

- **API:** call it from your code with dataset IDs, then read the run's dataset, or your named dataset, through the Apify API or client libraries.
- **Schedules:** run it on a schedule with **Keep: the last one** and a **Named dataset**.
  - Each run adds rows to the named dataset; it does not remove duplicates already saved there.
  - To dedupe against earlier output, merge the named dataset itself into a new name.

### FAQ

#### Is it legal to use?

Yes. It reads only datasets in your own Apify account, or ones you have access to, and doesn't contact any website.

#### What happens with a wrong dataset ID?

The run stops before outputting anything, says which ID it couldn't read and why, and charges nothing for rows. It never creates an empty dataset in place of a missing one.

#### How big can the datasets be?

- **Memory:** the Actor reads 1,000 rows at a time and remembers only a short fingerprint of each unique row, about 110 bytes. About 2 million unique rows fit in the default 512 MB. For more, raise the run's memory (up to 4 GB).
- **Time:** large merges take longer, mostly writing the output. Raise the run's timeout if needed.

#### Does it change my datasets?

No. It only reads them. The output goes to the run's own dataset or to the named dataset you choose.

#### Can it write to a named dataset I made elsewhere?

- **Not under its default limited permissions.** It writes to named datasets it created itself, and keeps access to them in later runs.
- **Workaround:** pick a new name, or merge your existing dataset in as an input.

# Actor input Schema

## `datasetIds` (type: `array`):

The datasets to merge, in order. Pick the results of earlier runs, or paste dataset IDs. A run ID is not a dataset ID: open the run, then Storage, to find its dataset.

## `rows` (type: `array`):

Optional rows given directly, as a JSON array of objects. Added after the datasets.

## `keyFields` (type: `array`):

Field(s) that identify a row, such as url or id; nested fields as address.city. Rows with the same values in all of them are duplicates. Values compare as text, so 42 and "42" match. Leave empty to compare whole rows. Rows with no value in any of these fields are all kept.

## `keep` (type: `string`):

Which row of each set of duplicates to keep. The last one is the newest when your datasets are in date order. Keeping the last reads the datasets twice.

## `fields` (type: `array`):

Only these fields, in this order. Rename with "as", e.g. address.city as city. Nested fields use dots. Missing fields come out empty (null). Leave empty to keep every field as it is.

## `outputDataset` (type: `string`):

Optional. Save the rows to a dataset with this name (letters, digits and hyphens) instead of the run's own dataset, which then gets one summary row. The first run creates it; later runs with the same name add to it. Named datasets are kept until you delete them.

## `maxRows` (type: `integer`):

Stop after outputting this many rows. 0 means no limit.

## Actor input object example

```json
{
  "rows": [
    {
      "name": "Example Ltd",
      "url": "https://example.com",
      "city": "London"
    },
    {
      "name": "Sample Inc",
      "url": "https://example.org",
      "city": "Austin"
    },
    {
      "name": "Example Ltd",
      "url": "https://example.com",
      "city": "London"
    }
  ],
  "keep": "first",
  "maxRows": 0
}
```

# Actor output Schema

## `results` (type: `string`):

The merged rows without duplicates (or one summary row when you chose a named dataset for the output).

## `runSummary` (type: `string`):

Rows read and output, duplicates skipped, each dataset read and anything that stopped the run, saved as RUN_SUMMARY.

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {
    "rows": [
        {
            "name": "Example Ltd",
            "url": "https://example.com",
            "city": "London"
        },
        {
            "name": "Sample Inc",
            "url": "https://example.org",
            "city": "Austin"
        },
        {
            "name": "Example Ltd",
            "url": "https://example.com",
            "city": "London"
        }
    ]
};

// Run the Actor and wait for it to finish
const run = await client.actor("subtleasianmerch/dataset-merge-dedupe").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = { "rows": [
        {
            "name": "Example Ltd",
            "url": "https://example.com",
            "city": "London",
        },
        {
            "name": "Sample Inc",
            "url": "https://example.org",
            "city": "Austin",
        },
        {
            "name": "Example Ltd",
            "url": "https://example.com",
            "city": "London",
        },
    ] }

# Run the Actor and wait for it to finish
run = client.actor("subtleasianmerch/dataset-merge-dedupe").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print(f"💾 Check your data here: https://console.apify.com/storage/datasets/{run.default_dataset_id}")
for item in client.dataset(run.default_dataset_id).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{
  "rows": [
    {
      "name": "Example Ltd",
      "url": "https://example.com",
      "city": "London"
    },
    {
      "name": "Sample Inc",
      "url": "https://example.org",
      "city": "Austin"
    },
    {
      "name": "Example Ltd",
      "url": "https://example.com",
      "city": "London"
    }
  ]
}' |
apify call subtleasianmerch/dataset-merge-dedupe --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,subtleasianmerch/dataset-merge-dedupe"
        }
    }
}
```

The hosted server signs you in with OAuth on first connect, so no API token belongs in this config. Clients without OAuth support can send an `Authorization: Bearer <APIFY_API_TOKEN>` header instead, using a token from API & Integrations in Apify Console (https://console.apify.com/settings/integrations).

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/60V4bffPb5k5lrCPW/builds/t2PPZCwCRVtb9HSwl/openapi.json
