 <p>If you think about the overall operation that you are trying to perform, it is really just a Wipe-and-Replace based on what you are passing in. According to your stated rules:</p> <ul> <li>if I send parameter with CrateID = 2 and FruitID = 4, I want it to add another row (<em>assumption is that no rows exist yet for CrateID = 2</em>)</li> <li>if rows already exist for CrateID = 2: delete all records where CrateID = 2 and then add new records I am sending in parameter, don't touch another CrateIDs</li> </ul> <p>Hence, you shouldn't be using <code>MERGE</code> for this. Instead, just do:</p> <pre class="lang-sql prettyprint-override"><code>DELETE fc FROM Fruits_Crates fc WHERE fc.CrateID IN (SELECT DISTINCT tmp.CrateID FROM #FruitCrates tmp); INSERT INTO Fruits_Crates (FruitID, CrateID) SELECT tmp.FruitID, tmp.CrateID FROM FruitCrates tmp; </code></pre> <p>Or, if most of the time the number of items that match exceeds the number of items that will be removed and added, you can take a more targeted approach:</p> <pre class="lang-sql prettyprint-override"><code>CREATE TABLE #FruitCrates (FruitID INT, CrateID INT); CREATE TABLE #Fruits_Crates (FruitID INT, CrateID INT); --DELETE FROM #FruitCrates INSERT INTO #FruitCrates (CrateID, FruitID) VALUES (2, 4); INSERT INTO #FruitCrates (CrateID, FruitID) VALUES (2, 6); INSERT INTO #FruitCrates (CrateID, FruitID) VALUES (3, 26); --DELETE FROM #Fruits_Crates; INSERT INTO #Fruits_Crates (CrateID, FruitID) VALUES (1, 4); INSERT INTO #Fruits_Crates (CrateID, FruitID) VALUES (2, 4); INSERT INTO #Fruits_Crates (CrateID, FruitID) VALUES (2, 8); DELETE fc --SELECT fc.*, '--' AS [--], tmp.* FROM #Fruits_Crates fc LEFT JOIN #FruitCrates tmp ON tmp.CrateID = fc.CrateID AND tmp.FruitID = fc.FruitID WHERE tmp.CrateID IS NULL AND fc.CrateID IN (SELECT DISTINCT tmp2.CrateID FROM #FruitCrates tmp2); INSERT INTO #Fruits_Crates (FruitID, CrateID) SELECT tmp.FruitID, tmp.CrateID FROM #FruitCrates tmp LEFT JOIN #Fruits_Crates fc ON fc.CrateID = tmp.CrateID AND fc.FruitID = tmp.FruitID WHERE fc.CrateID IS NULL; SELECT CrateID, FruitID FROM #Fruits_Crates; </code></pre> <p>Output:</p> <pre class="lang-none prettyprint-override"><code>CrateID FruitID 1 4 2 4 2 6 3 26 </code></pre> <p>Result:</p> <ul> <li>Row with CrateID = 1, FruitID = 4: <strong>left alone</strong></li> <li>Row with CrateID = 2, FruitID = 4: <strong>left alone</strong></li> <li>Row with CrateID = 2, FruitID = 8: <strong>removed</strong></li> <li>Row with CrateID = 2, FruitID = 6: <strong>added</strong></li> <li>Row with CrateID = 3, FruitID = 26: <strong>added</strong></li> </ul>