How to prevent duplicate records when using MERGE INTO?

dataumer
New Contributor

hello guys

What is the best way to handle a source dataset that contains multiple records for the same business key before performing a MERGE into a Delta table?

For example, the same customer ID may appear multiple times with different update timestamps.

Would using ROW_NUMBER() to retain the latest record be sufficient? How should we handle cases where multiple records have the same timestamp?