<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>article Improved Duplicate Match Handling in Delta MERGE Operations in Technical Blog</title>
    <link>https://community.databricks.com/t5/technical-blog/improved-duplicate-match-handling-in-delta-merge-operations/ba-p/106537</link>
    <description>&lt;P&gt;&lt;SPAN&gt;In DBR 16.1+, we’ve improved functionality of &lt;/SPAN&gt;&lt;FONT face="courier new,courier"&gt;&lt;SPAN&gt;MERGE&lt;/SPAN&gt;&lt;/FONT&gt;&lt;SPAN&gt; operations where multiple rows of the source dataset match the same row of the target Delta table, but only one row matches the &lt;/SPAN&gt;&lt;FONT face="courier new,courier"&gt;&lt;SPAN&gt;WHEN MATCHED&lt;/SPAN&gt;&lt;/FONT&gt;&lt;SPAN&gt; condition.&amp;nbsp; In the past, these operations would fail with &lt;/SPAN&gt;&lt;FONT face="courier new,courier"&gt;&lt;SPAN&gt;DELTA_MULTIPLE_SOURCE_ROW_MATCHING_TARGET_ROW_IN_MERGE&lt;/SPAN&gt;&lt;/FONT&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Prior DBR’s&amp;nbsp;&lt;FONT face="courier new,courier"&gt;MERGE&lt;/FONT&gt;&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;would only use the&amp;nbsp;&lt;FONT face="courier new,courier"&gt;MERGE&lt;/FONT&gt;&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;conditions to detect multiple rows from the source dataset trying to update the target dataset leading to ambiguity.&amp;nbsp; This improved functionality allows for the&amp;nbsp;&lt;FONT face="courier new,courier"&gt;WHEN MATCHED&lt;/FONT&gt;&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;condition to help resolve the ambiguity.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;As an example, let's take a look at a&amp;nbsp;&lt;FONT face="courier new,courier"&gt;MERGE&lt;/FONT&gt;&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;that will now succeed in DBR 16.1+.&lt;/SPAN&gt;&lt;/P&gt;
&lt;TABLE style="border-style: hidden; width: 100%;" border="0" width="100%"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="100%"&gt;&lt;LI-CODE lang="ruby"&gt;MERGE INTO t USING s
ON t.id = s.id 
WHEN MATCHED AND s.value = 'b' 
THEN UPDATE SET *
WHEN NOT MATCHED 
THEN INSERT *&lt;/LI-CODE&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&lt;STRONG&gt;Target Table&lt;BR /&gt;&lt;BR /&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;TABLE class=" lia-indent-margin-left-30px"&gt;
&lt;TBODY class="lia-indent-padding-left-30px"&gt;
&lt;TR class="lia-indent-padding-left-30px"&gt;
&lt;TD class="lia-indent-padding-left-30px"&gt;
&lt;P class="lia-indent-padding-left-30px"&gt;&lt;STRONG&gt;ID&lt;/STRONG&gt;&lt;/P&gt;
&lt;/TD&gt;
&lt;TD class="lia-indent-padding-left-30px"&gt;
&lt;P class="lia-indent-padding-left-30px"&gt;&lt;STRONG&gt;Value&lt;/STRONG&gt;&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR class="lia-indent-padding-left-30px"&gt;
&lt;TD class="lia-indent-padding-left-30px"&gt;
&lt;P class="lia-indent-padding-left-30px"&gt;&lt;SPAN&gt;1&lt;/SPAN&gt;&lt;/P&gt;
&lt;/TD&gt;
&lt;TD class="lia-indent-padding-left-30px"&gt;
&lt;P class="lia-indent-padding-left-30px"&gt;&lt;SPAN&gt;a&lt;/SPAN&gt;&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&lt;STRONG&gt;Source Table&lt;BR /&gt;&lt;BR /&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;TABLE class=" lia-indent-margin-left-30px" width="187px"&gt;
&lt;TBODY class="lia-indent-padding-left-30px"&gt;
&lt;TR class="lia-indent-padding-left-30px"&gt;
&lt;TD width="82px" class="lia-indent-padding-left-30px"&gt;
&lt;P class="lia-indent-padding-left-30px"&gt;&lt;STRONG&gt;ID&lt;/STRONG&gt;&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="105.742px" class="lia-indent-padding-left-30px"&gt;
&lt;P class="lia-indent-padding-left-30px"&gt;&lt;STRONG&gt;Value&lt;/STRONG&gt;&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR class="lia-indent-padding-left-30px"&gt;
&lt;TD width="82px" class="lia-indent-padding-left-30px"&gt;
&lt;P class="lia-indent-padding-left-30px"&gt;&lt;SPAN&gt;1&lt;/SPAN&gt;&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="105.742px" class="lia-indent-padding-left-30px"&gt;
&lt;P class="lia-indent-padding-left-30px"&gt;&lt;SPAN&gt;b&lt;/SPAN&gt;&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR class="lia-indent-padding-left-30px"&gt;
&lt;TD width="82px" class="lia-indent-padding-left-30px"&gt;
&lt;P class="lia-indent-padding-left-30px"&gt;&lt;SPAN&gt;1&lt;/SPAN&gt;&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="105.742px" class="lia-indent-padding-left-30px"&gt;
&lt;P class="lia-indent-padding-left-30px"&gt;&lt;SPAN&gt;c&lt;/SPAN&gt;&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P class="lia-indent-padding-left-30px"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;In this example, the source has two matching rows that could be used to update the target table.&amp;nbsp; The &lt;/SPAN&gt;&lt;FONT face="courier new,courier"&gt;&lt;SPAN&gt;WHEN MATCHED&lt;/SPAN&gt;&lt;/FONT&gt;&lt;SPAN&gt; condition reduces the matching rows from two matches to one match.&amp;nbsp; When running this with an older DBR, it would fail with &lt;/SPAN&gt;&lt;FONT face="courier new,courier"&gt;&lt;SPAN&gt;DELTA_MULTIPLE_SOURCE_ROW_MATCHING_TARGET_ROW_IN_MERGE&lt;/SPAN&gt;&lt;/FONT&gt;&lt;SPAN&gt;, even though the &lt;/SPAN&gt;&lt;FONT face="courier new,courier"&gt;&lt;SPAN&gt;WHEN MATCHED&lt;/SPAN&gt;&lt;/FONT&gt;&lt;SPAN&gt; condition reduced the matches to one.&amp;nbsp; The improved functionality in DBR 16.1+ will allow this to succeed&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Tue, 04 Feb 2025 01:39:33 GMT</pubDate>
    <dc:creator>joe_widen</dc:creator>
    <dc:date>2025-02-04T01:39:33Z</dc:date>
    <item>
      <title>Improved Duplicate Match Handling in Delta MERGE Operations</title>
      <link>https://community.databricks.com/t5/technical-blog/improved-duplicate-match-handling-in-delta-merge-operations/ba-p/106537</link>
      <description>&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Avnish_Jain_0-1738632862156.png" style="width: 400px;"&gt;&lt;img src="https://community.databricks.com/t5/image/serverpage/image-id/14571i9B5AF91CC3BDB306/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Avnish_Jain_0-1738632862156.png" alt="Avnish_Jain_0-1738632862156.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 04 Feb 2025 01:39:33 GMT</pubDate>
      <guid>https://community.databricks.com/t5/technical-blog/improved-duplicate-match-handling-in-delta-merge-operations/ba-p/106537</guid>
      <dc:creator>joe_widen</dc:creator>
      <dc:date>2025-02-04T01:39:33Z</dc:date>
    </item>
    <item>
      <title>Re: Improved Duplicate Match Handling in Delta MERGE Operations</title>
      <link>https://community.databricks.com/t5/technical-blog/improved-duplicate-match-handling-in-delta-merge-operations/bc-p/108957#M454</link>
      <description>&lt;P&gt;What happens in DBRS 16.1 if the WHEN condition is this:&lt;BR /&gt;&lt;BR /&gt;WHEN MATCHED AND s.value IS DISTINCT FROM t.value&lt;BR /&gt;&lt;BR /&gt;Basically saying when it matches on the PK but then check if the other columns are different before taking an action like UPDATE.&lt;/P&gt;</description>
      <pubDate>Wed, 05 Feb 2025 13:24:14 GMT</pubDate>
      <guid>https://community.databricks.com/t5/technical-blog/improved-duplicate-match-handling-in-delta-merge-operations/bc-p/108957#M454</guid>
      <dc:creator>BamBam</dc:creator>
      <dc:date>2025-02-05T13:24:14Z</dc:date>
    </item>
    <item>
      <title>Re: Improved Duplicate Match Handling in Delta MERGE Operations</title>
      <link>https://community.databricks.com/t5/technical-blog/improved-duplicate-match-handling-in-delta-merge-operations/bc-p/109330#M459</link>
      <description>&lt;P&gt;This is a great solution! The improved duplicate match handling in Delta MERGE operations in DBR 16.1+ is a significant enhancement, as it resolves ambiguity and ensures smoother operations by leveraging the&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;WHEN MATCHED&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;condition. This update not only simplifies workflows but also reduces errors, making data management more efficient. Well done!&lt;/P&gt;&lt;P&gt;I have a humble question: Are there any recommended cost optimization strategies that can be applied alongside this improved functionality, especially for large-scale MERGE operations? For instance, how can we ensure efficient resource utilization while maintaining performance during such operations? Thank you!&lt;/P&gt;</description>
      <pubDate>Thu, 06 Feb 2025 23:43:33 GMT</pubDate>
      <guid>https://community.databricks.com/t5/technical-blog/improved-duplicate-match-handling-in-delta-merge-operations/bc-p/109330#M459</guid>
      <dc:creator>Mantsama4</dc:creator>
      <dc:date>2025-02-06T23:43:33Z</dc:date>
    </item>
    <item>
      <title>Re: Improved Duplicate Match Handling in Delta MERGE Operations</title>
      <link>https://community.databricks.com/t5/technical-blog/improved-duplicate-match-handling-in-delta-merge-operations/bc-p/115021#M512</link>
      <description>&lt;P&gt;The following example made this more clear for me:&lt;/P&gt;
&lt;P&gt;MERGE .... ON source.id = target.id &lt;BR /&gt;WHEN MATCHED AND source.value = target.value&lt;BR /&gt;WHEN NOT MATCHED THEN INSERT&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screenshot 2025-04-08 at 10.44.42 AM.png" style="width: 999px;"&gt;&lt;img src="https://community.databricks.com/t5/image/serverpage/image-id/15896i3403017A92BAE385/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screenshot 2025-04-08 at 10.44.42 AM.png" alt="Screenshot 2025-04-08 at 10.44.42 AM.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 09 Apr 2025 16:37:31 GMT</pubDate>
      <guid>https://community.databricks.com/t5/technical-blog/improved-duplicate-match-handling-in-delta-merge-operations/bc-p/115021#M512</guid>
      <dc:creator>StephanieAlba</dc:creator>
      <dc:date>2025-04-09T16:37:31Z</dc:date>
    </item>
    <item>
      <title>Re: Improved Duplicate Match Handling in Delta MERGE Operations</title>
      <link>https://community.databricks.com/t5/technical-blog/improved-duplicate-match-handling-in-delta-merge-operations/bc-p/115032#M513</link>
      <description>&lt;P&gt;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/1418"&gt;@StephanieAlba&lt;/a&gt;&amp;nbsp; &amp;nbsp;So that means sense... so using your data scenario above if we have something like this that uses a IS DISTINCT FROM instead of the "=" (shown below) then we will get an error, correct?&amp;nbsp; It will still try to update two records, which is not allowed.&amp;nbsp; Correct?&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;MERGE .... ON source.id = target.id&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;WHEN MATCHED AND source.value &lt;U&gt;IS DISTINCT FROM&lt;/U&gt; target.value&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;WHEN NOT MATCHED THEN INSERT&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 09 Apr 2025 17:03:14 GMT</pubDate>
      <guid>https://community.databricks.com/t5/technical-blog/improved-duplicate-match-handling-in-delta-merge-operations/bc-p/115032#M513</guid>
      <dc:creator>BamBam</dc:creator>
      <dc:date>2025-04-09T17:03:14Z</dc:date>
    </item>
    <item>
      <title>Re: Improved Duplicate Match Handling in Delta MERGE Operations</title>
      <link>https://community.databricks.com/t5/technical-blog/improved-duplicate-match-handling-in-delta-merge-operations/bc-p/115046#M515</link>
      <description>&lt;P&gt;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/1418"&gt;@StephanieAlba&lt;/a&gt;&amp;nbsp;That is unfortunate and will be a breaking change.&amp;nbsp; Is there any setting or SQL clause that would make this MERGE error fail in DBRS 16.0+ given the above scenario?&lt;/P&gt;</description>
      <pubDate>Wed, 09 Apr 2025 17:59:28 GMT</pubDate>
      <guid>https://community.databricks.com/t5/technical-blog/improved-duplicate-match-handling-in-delta-merge-operations/bc-p/115046#M515</guid>
      <dc:creator>BamBam</dc:creator>
      <dc:date>2025-04-09T17:59:28Z</dc:date>
    </item>
    <item>
      <title>Re: Improved Duplicate Match Handling in Delta MERGE Operations</title>
      <link>https://community.databricks.com/t5/technical-blog/improved-duplicate-match-handling-in-delta-merge-operations/bc-p/115050#M516</link>
      <description>&lt;P&gt;Oops. I thought I could edit my previous comment. Also, I checked with eng folks and this below is correct.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screenshot 2025-04-08 at 10.44.42 AM.png" style="width: 999px;"&gt;&lt;img src="https://community.databricks.com/t5/image/serverpage/image-id/15905iEAEC5A87A5E2C6A6/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screenshot 2025-04-08 at 10.44.42 AM.png" alt="Screenshot 2025-04-08 at 10.44.42 AM.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screenshot 2025-04-08 at 10.44.42 AM copy.png" style="width: 999px;"&gt;&lt;img src="https://community.databricks.com/t5/image/serverpage/image-id/15903i3B84135214EE2651/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screenshot 2025-04-08 at 10.44.42 AM copy.png" alt="Screenshot 2025-04-08 at 10.44.42 AM copy.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 09 Apr 2025 18:14:53 GMT</pubDate>
      <guid>https://community.databricks.com/t5/technical-blog/improved-duplicate-match-handling-in-delta-merge-operations/bc-p/115050#M516</guid>
      <dc:creator>StephanieAlba</dc:creator>
      <dc:date>2025-04-09T18:14:53Z</dc:date>
    </item>
    <item>
      <title>Re: Improved Duplicate Match Handling in Delta MERGE Operations</title>
      <link>https://community.databricks.com/t5/technical-blog/improved-duplicate-match-handling-in-delta-merge-operations/bc-p/115058#M517</link>
      <description>&lt;P&gt;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/1418"&gt;@StephanieAlba&lt;/a&gt;&amp;nbsp;-&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Run this SQL:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;CREATE TABLE bronze.temp.temp_source (source_id INT, source_first_name STRING, source_last_name STRING);

CREATE TABLE bronze.temp.temp_target (target_id INT, target_first_name STRING, target_last_name STRING);

INSERT INTO bronze.temp.temp_source
VALUES(1,'John','Avery'),(2,'Jack','Rodgers');


-- INSERTED 2 records correctly
MERGE INTO bronze.temp.temp_target AS DEST 
USING (
	SELECT 
		source_id
		, source_first_name
		, source_last_name
	FROM bronze.temp.temp_source
) AS SRC
ON DEST.target_id = SRC.source_id
WHEN MATCHED AND (
	DEST.target_first_name IS DISTINCT FROM SRC.source_first_name
	OR DEST.target_last_name IS DISTINCT FROM SRC.source_last_name
)
THEN UPDATE SET 
	DEST.target_first_name = SRC.source_first_name
	, DEST.target_last_name = SRC.source_last_name
WHEN NOT MATCHED THEN
INSERT (
	DEST.target_id
	, DEST.target_first_name
	, DEST.target_last_name
)
VALUES
(
	SRC.source_id
	, SRC.source_first_name
	, SRC.source_last_name
)
;

UPDATE bronze.temp.temp_source
SET source_first_name = 'Randy'
WHERE source_id = 1;

-- Rerun MERGE.. 1 row updated as expected

INSERT INTO bronze.temp.temp_source
VALUES(1,'Greg','Nelson');

-- Rerun MERGE.. 1 row updated... &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;  It should have errored.
-- Rerunning the merge over and over again just keeps changing the record.


INSERT INTO bronze.temp.temp_source
VALUES(1,'Mary','Wilson');

-- Rerun MERGE... now there are 3 records with an ID = 1.  The MERGE above fails.&lt;/LI-CODE&gt;&lt;P&gt;If there are two rows with an ID = 1, then the MERGE just keeps updating every time you run.&amp;nbsp; If there are three rows with an ID = 1, then the MERGE will fail.&amp;nbsp; Kinda crazy.&lt;/P&gt;&lt;P&gt;We really need an option, setting or clause in this MERGE statement to allow it to behave like DBRS &amp;lt;= 16+ that would fail if it finds more than one record.&amp;nbsp; Thoughts?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 09 Apr 2025 19:50:24 GMT</pubDate>
      <guid>https://community.databricks.com/t5/technical-blog/improved-duplicate-match-handling-in-delta-merge-operations/bc-p/115058#M517</guid>
      <dc:creator>BamBam</dc:creator>
      <dc:date>2025-04-09T19:50:24Z</dc:date>
    </item>
    <item>
      <title>Re: Improved Duplicate Match Handling in Delta MERGE Operations</title>
      <link>https://community.databricks.com/t5/technical-blog/improved-duplicate-match-handling-in-delta-merge-operations/bc-p/115059#M518</link>
      <description>&lt;P&gt;Tested it! Here you go&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;# Sample data
data = [("1", "A", 30), ("2", "A", 25), ("3", "B", 35)]
columns = ["ID", "Letter", "Value"]

# Create DataFrame
df = spark.createDataFrame(data, columns)

df.write.mode("overwrite").saveAsTable("test_data")&lt;/LI-CODE&gt;
&lt;DIV&gt;
&lt;DIV&gt;&amp;nbsp;Look at the data quick&lt;LI-CODE lang="python"&gt;select * from test_data​&lt;/LI-CODE&gt;&lt;/DIV&gt;
&lt;DIV&gt;
&lt;P&gt;Try merging bad data&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;MERGE INTO test_data t 
USING (SELECT * FROM VALUES 
            ("1", "A", 31), 
            ("1", "A", 25), 
            ("3", "B", 36)) s
ON t.ID = s.col1
WHEN MATCHED AND t.Letter = s.col2 THEN 
    UPDATE SET t.ID = s.col1, t.Letter = s.col2, t.Value = s.col3
WHEN NOT MATCHED THEN INSERT (`ID`, `Letter`, `Value`) VALUES (s.col1, s.col2, s.col3);&lt;/LI-CODE&gt;
&lt;P&gt;Throws and error &lt;FONT face="courier new,courier"&gt;&lt;SPAN&gt;[&lt;/SPAN&gt;&lt;A class="du-bois-light-typography css-cs8bxj" href="https://docs.databricks.com/error-messages/error-classes.html#delta_multiple_source_row_matching_target_row_in_merge" target="_blank" rel="noopener noreferrer" data-component-id="notebook.command.output.errorClass.link" data-component-type="typography_link"&gt;DELTA_MULTIPLE_SOURCE_ROW_MATCHING_TARGET_ROW_IN_MERGE&lt;/A&gt;&lt;SPAN&gt;]&lt;/SPAN&gt;&lt;SPAN&gt; Cannot perform Merge as multiple source rows matched and attempted to modify the same target row in the Delta table in possibly conflicting ways. By SQL semantics of Merge, when multiple source rows match on the same target row, the result may be ambiguous&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;&lt;SPAN&gt;Try merging good data&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;MERGE INTO test_data t 
USING (SELECT * FROM VALUES 
            ("1", "A", 31), 
            ("1", "D", 25), 
            ("3", "B", 36)) s
ON t.ID = s.col1
WHEN MATCHED AND t.Letter = s.col2 THEN 
    UPDATE SET t.ID = s.col1, t.Letter = s.col2, t.Value = s.col3
WHEN NOT MATCHED THEN INSERT (`ID`, `Letter`, `Value`) VALUES (s.col1, s.col2, s.col3);&lt;/LI-CODE&gt;
&lt;P&gt;Check the updates!&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;select * from test_data&lt;/LI-CODE&gt;&lt;/DIV&gt;
&lt;/DIV&gt;</description>
      <pubDate>Wed, 09 Apr 2025 19:53:36 GMT</pubDate>
      <guid>https://community.databricks.com/t5/technical-blog/improved-duplicate-match-handling-in-delta-merge-operations/bc-p/115059#M518</guid>
      <dc:creator>StephanieAlba</dc:creator>
      <dc:date>2025-04-09T19:53:36Z</dc:date>
    </item>
    <item>
      <title>Re: Improved Duplicate Match Handling in Delta MERGE Operations</title>
      <link>https://community.databricks.com/t5/technical-blog/improved-duplicate-match-handling-in-delta-merge-operations/bc-p/115060#M519</link>
      <description>&lt;P&gt;Hey&amp;nbsp;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/63866"&gt;@BamBam&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;I see your code now. I am testing it.&lt;/P&gt;
&lt;PRE class="lia-code-sample  language-markup"&gt;&lt;CODE&gt;INSERT INTO bronze.temp.temp_source
VALUES(1,'Greg','Nelson');

-- Rerun MERGE.. 1 row updated... &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;  It should have errored.&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I am confused. The names are different, so it should be updated.&lt;/P&gt;</description>
      <pubDate>Wed, 09 Apr 2025 20:16:20 GMT</pubDate>
      <guid>https://community.databricks.com/t5/technical-blog/improved-duplicate-match-handling-in-delta-merge-operations/bc-p/115060#M519</guid>
      <dc:creator>StephanieAlba</dc:creator>
      <dc:date>2025-04-09T20:16:20Z</dc:date>
    </item>
    <item>
      <title>Re: Improved Duplicate Match Handling in Delta MERGE Operations</title>
      <link>https://community.databricks.com/t5/technical-blog/improved-duplicate-match-handling-in-delta-merge-operations/bc-p/115064#M520</link>
      <description>&lt;P&gt;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/1418"&gt;@StephanieAlba&lt;/a&gt;&amp;nbsp; - Thanks for trying that code.&amp;nbsp; Sorry in the DBRS 15.4 this would have failed because it has two ID = 1 records.&amp;nbsp; In DBRS 16.x it doesn't fail.&amp;nbsp; Yes, see if you can get the DBRS 16.x to fail when there are three ID = 1 records, but it doesn't fail if there are two ID = 1 records.&amp;nbsp; That was the unusual part.&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 09 Apr 2025 20:47:37 GMT</pubDate>
      <guid>https://community.databricks.com/t5/technical-blog/improved-duplicate-match-handling-in-delta-merge-operations/bc-p/115064#M520</guid>
      <dc:creator>BamBam</dc:creator>
      <dc:date>2025-04-09T20:47:37Z</dc:date>
    </item>
    <item>
      <title>Re: Improved Duplicate Match Handling in Delta MERGE Operations</title>
      <link>https://community.databricks.com/t5/technical-blog/improved-duplicate-match-handling-in-delta-merge-operations/bc-p/115202#M521</link>
      <description>&lt;P&gt;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/63866"&gt;@BamBam&lt;/a&gt;&amp;nbsp;I tried it, but didn't get an error. What am I missing? See below:&lt;/P&gt;
&lt;P&gt;Sample example just adding some new values for insert.&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;MERGE INTO test_data t 
USING (SELECT * FROM VALUES 
            ("4", "A", 1), 
            ("4", "D", 2), 
            ("4", "B", 3)) s
ON t.ID = s.col1
WHEN MATCHED AND t.Letter = s.col2 THEN 
    UPDATE SET t.ID = s.col1, t.Letter = s.col2, t.Value = s.col3
WHEN NOT MATCHED THEN INSERT (`ID`, `Letter`, `Value`) VALUES (s.col1, s.col2, s.col3);&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;[works] Attempting to merge rows with IDs = 4 and matching only on one&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;MERGE INTO test_data t 
USING (SELECT * FROM VALUES 
            ("4", "A", 4), 
            ("4", "E", 5), 
            ("4", "G", 6)) s
ON t.ID = s.col1
WHEN MATCHED AND t.Letter = s.col2 THEN 
    UPDATE SET t.ID = s.col1, t.Letter = s.col2, t.Value = s.col3
WHEN NOT MATCHED THEN INSERT (`ID`, `Letter`, `Value`) VALUES (s.col1, s.col2, s.col3);&lt;/LI-CODE&gt;
&lt;P&gt;[works] Adding 3 rows all matched&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;MERGE INTO test_data t 
USING (SELECT * FROM VALUES 
            ("4", "A", 7), 
            ("4", "B", 8), 
            ("4", "D", 9)) s
ON t.ID = s.col1
WHEN MATCHED AND t.Letter = s.col2 THEN 
    UPDATE SET t.ID = s.col1, t.Letter = s.col2, t.Value = s.col3
WHEN NOT MATCHED THEN INSERT (`ID`, `Letter`, `Value`) VALUES (s.col1, s.col2, s.col3);&lt;/LI-CODE&gt;
&lt;P&gt;[fails] Two conflicting matches&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;MERGE INTO test_data t 
USING (SELECT * FROM VALUES 
            ("4", "A", 10), 
            ("4", "A", 11), 
            ("4", "Q", 12)) s
ON t.ID = s.col1
WHEN MATCHED AND t.Letter = s.col2 THEN 
    UPDATE SET t.ID = s.col1, t.Letter = s.col2, t.Value = s.col3
WHEN NOT MATCHED THEN INSERT (`ID`, `Letter`, `Value`) VALUES (s.col1, s.col2, s.col3);&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 10 Apr 2025 19:02:07 GMT</pubDate>
      <guid>https://community.databricks.com/t5/technical-blog/improved-duplicate-match-handling-in-delta-merge-operations/bc-p/115202#M521</guid>
      <dc:creator>StephanieAlba</dc:creator>
      <dc:date>2025-04-10T19:02:07Z</dc:date>
    </item>
    <item>
      <title>Re: Improved Duplicate Match Handling in Delta MERGE Operations</title>
      <link>https://community.databricks.com/t5/technical-blog/improved-duplicate-match-handling-in-delta-merge-operations/bc-p/116605#M539</link>
      <description>&lt;P&gt;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/63866"&gt;@BamBam&lt;/a&gt;&amp;nbsp;you can email me use my first name at databricks.com&lt;/P&gt;</description>
      <pubDate>Fri, 25 Apr 2025 16:32:39 GMT</pubDate>
      <guid>https://community.databricks.com/t5/technical-blog/improved-duplicate-match-handling-in-delta-merge-operations/bc-p/116605#M539</guid>
      <dc:creator>StephanieAlba</dc:creator>
      <dc:date>2025-04-25T16:32:39Z</dc:date>
    </item>
  </channel>
</rss>

