title: Oracle SQL | Merge-Select-Update Clause | Subset of Target Table
body: <p><strong><em>What I intend to do?</em></strong><br>
  To update a few target table fields for sub-set of matched target records, getting matched between source and target, provided they both being the same table.  </p>
  
  <p><strong><em>Where I need help?</em></strong><br>
  <code>Merge-into-</code><em>target</em><code>-using-select-</code><em>source</em><code>-on-</code> clause seems to have control only for two categories-  </p>
  
  <ul>
  <li>When Source and Target records match, update <strong>all</strong> matching target records</li>
  <li>When Source and Target records does not match, <strong>insert</strong> or perform other control operations.  </li>
  </ul>
  
  <p>In my case, When Source and Target records match, I'd like to perform update on <strong>Not all</strong> records of target but on a <strong>sub-set of target records</strong>. </p>
  
  <p>Requesting help to guide on this.</p>
  
  <p>For reference here's the code(target filter qualifier commented, as it won't work for sure):</p>
  
  <pre><code>MERGE INTO TGT
  USING (
  SELECT id, account_number, part_role, inc_val, pay_frequency, 
  period, pay_option, inclusion_value 
  FROM Table_1
  WHERE id = var1
  AND account_number = var2
  AND part_role in ('YY','XX')
  ) SRC
  ON (
  SRC.id = TGT.id
  AND SRC.account_number = TGT.account_number
  --TGT.part_role in ('AA','BB','CC','DD','EE') --This must be a wrong place for this qualifier, please help on where to include this qualifier for filtering out target records for update purpose
  )
  WHEN MATCHED THEN
  UPDATE SET
  TGT.inc_val = SRC.inc_val 
  ,TGT.pay_frequency = SRC.pay_frequency 
  ,TGT.period = SRC.period 
  ,TGT.pay_option = SRC.pay_option 
  ,TGT.inclusion_value = SRC.inclusion_value;
  </code></pre>
  
  <p><strong>Other Associated Details</strong><br>
  Database: Oracle<br>
  Version: 11gR2<br>
  Environment: Unix</p>