# Handling Merge to update the existing records and inserting the New records

**URL:** <https://discourse.getdbt.com/t/handling-merge-to-update-the-existing-records-and-inserting-the-new-records/13471>\
**Category:** Help\
**Tags:** incremental, bigquery, dbt-core\
**Created:** [May 22, 2024, 5:09am UTC](https://discourse.getdbt.com/t/handling-merge-to-update-the-existing-records-and-inserting-the-new-records/13471 "2024-05-22T05:09:33Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![chandini](https://avatars.discourse-cdn.com/v4/letter/c/bbce88/32.png) [@chandini](https://discourse.getdbt.com/u/chandini)\
**Post date:** [May 22, 2024, 5:09am UTC](https://discourse.getdbt.com/t/handling-merge-to-update-the-existing-records-and-inserting-the-new-records/13471/1 "2024-05-22T05:09:33Z")

</div>

Hi Folks,  
I am new to dbt. Recently we are doing migration from Hive to BQ. We are converting all our ETL process to dbt. I am facing issue regarding Merge. how can I apply MERGE when some of conditions looks like:  
[  
…  
when matched and [col a] \<\> [col b]  
then update [col a] = [col b]

when not matched  
then insert  
values (  
col a,  
col b)  
…  
]  
I need to update rows only when matched and only when its not equals and also I need to insert the new records if not matched.

Thanks in advance

---

<div class="post-metadata">

**Author:** ![a\_slack\_user](https://sea2.discourse-cdn.com/flex020/user_avatar/discourse.getdbt.com/a_slack_user/32/1629_2.png) [@a\_slack\_user](https://discourse.getdbt.com/u/a_slack_user)\
**Post date:** [May 23, 2024, 3:41pm UTC](https://discourse.getdbt.com/t/handling-merge-to-update-the-existing-records-and-inserting-the-new-records/13471/2 "2024-05-23T15:41:44Z")

</div>

In dbt we don’t need to write a merge statement.  
Have a look at incremental models, you can specify a unique key so that it will do what you are after

[https://docs.getdbt.com/docs/build/incremental-models|https://docs.getdbt.com/docs/build/incremental-models](https://docs.getdbt.com/docs/build/incremental-models%7Chttps://docs.getdbt.com/docs/build/incremental-models)

Note: `@Meagan Palmer (Altis)` originally [posted this reply in Slack](https://getdbt.slack.com/archives/CBSQTAPLG/p1716478894837919?thread_ts=1716354600.662719&cid=CBSQTAPLG). It might not have transferred perfectly.
