title: MERGE UPSERT DOES NOT WORK WHEN NOT MATCHED
body: <p>ABC_TABLE holds history data based on UPDATED_TS column.
  Requirement is to load data from a CSV file and conditions is as below:</p>
  
  <ol>
  <li>Fetch the latest EMPLOYEE_NAME based on UPDATED_TS (query inside USING condition)</li>
  <li>In ON condition check, if the EMPLOYEE_NAME in CSV file does not match the EMPLOYEE_NAME fetched in the USING query, a new row should be inserted</li>
  <li>If a new TABLE_ID is present in the CSV file and the TABLE_ID does not  exist in ABC_TABLE, a new record should be inserted</li>
  </ol>
  
  <p>When executing below query, no rows get inserted for a new TABLE_ID, </p>
  
  <pre><code>  MERGE INTO ABC_TABLE T
    USING (SELECT EMPLOYEE_NAME
             FROM ABC_TABLE
            WHERE TABLE_ID = ?
              AND UPDATED_TS =
                  (SELECT MAX(UPDATED_TS) FROM ABC_TABLE WHERE TABLE_ID = ?)) S
    ON ((S.EMPLOYEE_NAME IS NULL AND ? IS NULL) OR ? = S.EMPLOYEE_NAME )
    WHEN NOT MATCHED THEN
      INSERT
  </code></pre>
  
  <p>/*
  insert statement here
  */</p>
  
  <p>Any help would be greatly appreciated.</p>