title: Deleting duplicates in Oracle SQL
body: <p>Currently, I use a table with no primary keys. So while loading the table, there are possibilities that duplicates may be loaded. </p>
  
  <p>I use an automated process to load the table and a delete script in that process deletes the dubplicates from the table. But records which are not duplicates also get deleted. I am not able to figure out why. Please give your inputs. </p>
  
  <p>Table Name : Employee</p>
  
  <p>Table after Loading before deletion script runs</p>
  
  <pre><code>EmpID   SalID   EmpName   EmpAddr     EmpZip    
   112     012     Smith      TN        641604    
   112     012     Smith      TN        641604    
   113     013     Steve      KA        560068    
   114     014     Rao        KA        560069    
   115     015     Ram        KA        560100    
   115     015     Ram        KA        560100    
  </code></pre>
  
  <p>Table after deletion script runs</p>
  
  <pre><code>EmpID   SalID   EmpName   EmpAddr     EmpZip    
   112     012     Smith      TN        641604    
   114     014     Rao        KA        560069    
   115     015     Ram        KA        560100    
  </code></pre>
  
  <p>Strangely, EmpId 113 is deleted, while EmpId 114 is retained. </p>
  
  <p>Below is the deletion script</p>
  
  <pre><code>DELETE FROM EMPLOYEE E1 WHERE EXISTS
  (SELECT 1 FROM EMPLOYEE E2 WHERE E2.EMPID = E1.EMPID 
  AND E2.SALID = E1.SALID AND E2.EMPNAME = E1.EMPNAME
  AND E2.EMPADDR = E1.EMPADDR AND E2.EMPZIP = E1.EMPZIP
  AND E2.ROWID &gt; E1.ROWID)
  </code></pre>
  
  <p>Kindly give your inputs on whats going wrong.</p>