snipt

Ctrl+h for KB shortcuts

SQL

Delete duplicate records in Oracle by Id

delete from duplicates where rowid not in ( SELECT MIN(rowid)
FROM duplicates GROUP BY id)
https://snipt.net/embed/008709c30a171cd7643eb5017d1b1b38/
/raw/008709c30a171cd7643eb5017d1b1b38/
008709c30a171cd7643eb5017d1b1b38
sql
SQL
2
2019-07-24T01:05:55
True
False
False
/api/public/snipt/55395/
delete-duplicate-records-in-oracle-by-id
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="k">delete</span> <span class="k">from</span> <span class="n">duplicates</span> <span class="k">where</span> <span class="n">rowid</span> <span class="k">not</span> <span class="k">in</span> <span class="p">(</span> <span class="k">SELECT</span> <span class="k">MIN</span><span class="p">(</span><span class="n">rowid</span><span class="p">)</span> </span><span id="L-2"><a name="L-2"></a><span class="k">FROM</span> <span class="n">duplicates</span> <span class="k">GROUP</span> <span class="k">BY</span> <span class="n">id</span><span class="p">)</span> </span></pre></div> </td></tr></table>