---
title: mergeInto
description: "DataFrame.mergeInto method in PySpark: Merges a set of updates, insertions, and deletions based on a source table into a target table."
canonical_url: https://docs.databricks.com/aws/en/pyspark/reference/classes/dataframe/mergeInto
---

# mergeInto

Merges a set of updates, insertions, and deletions based on a source table into a target table.

## Syntax

```
mergeInto(table: str, condition: Column)
```

## Parameters

| Parameter   | Type   | Description                                                                                          |
| ----------- | ------ | ---------------------------------------------------------------------------------------------------- |
| `table`     | str    | Target table name to merge into.                                                                     |
| `condition` | Column | The condition that determines whether a row in the target table matches one in the source DataFrame. |

## Returns

`MergeIntoWriter`: MergeIntoWriter to use further to specify how to merge the source DataFrame into the target table.

## Examples

```python
from pyspark.sql.functions import expr
source = spark.createDataFrame(
    [(14, "Tom"), (23, "Alice"), (16, "Bob")], ["id", "name"])
(source.mergeInto("target", "id")
    .whenMatched().update({ "name": source.name })
    .whenNotMatched().insertAll()
    .whenNotMatchedBySource().delete()
    .merge())
```
