title: Left Join with Distinct Clause
body: <p>Below is my insert query.</p>
  
  <pre><code>INSERT INTO /*+ APPEND*/ TEMP_CUSTPARAM(CUSTNO, RATING)
  SELECT DISTINCT Q.CUSTNO, NVL(((NVL(P.RATING,0) * '10.0')/100),0) AS RATING
  FROM TB_ACCOUNTS Q LEFT JOIN TB_CUSTPARAM P
  ON P.TEXT_PARAM IN (SELECT DISTINCT PRDCD FROM TB_ACCOUNTS)
  AND P.TABLENAME='TB_ACCOUNTS' AND P.COLUMNNAME='PRDCD';
  </code></pre>
  
  <p>In the previous version of the query, <code>P.TEXT_PARAM=Q.PRDCD</code> but during insert to <code>TEMP_CUSTPARAM</code> due to violation of unique constraint on <code>CUSTNO</code>.</p>
  
  <p>The insert query is taking ages to complete. Would like to know how to use distinct with <code>LEFT JOIN</code> statement.</p>
  
  <p>Thanks.</p>