snipt

Ctrl+h for KB shortcuts

MySQL

Finding duplicate records in mysql

1
2
3
4
5
SELECT title, COUNT(title) AS num_found
FROM articles
GROUP BY title
HAVING num_found > 1
ORDER BY num_found DESC;
https://snipt.net/embed/fda42d21d2b6ec448a154963753734d3/
/raw/fda42d21d2b6ec448a154963753734d3/
fda42d21d2b6ec448a154963753734d3
mysql
MySQL
5
2019-07-06T08:55:19
True
False
False
/api/public/snipt/22053/
finding-duplicate-records-in-mysql
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a> <a href="#L-5">5</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">SELECT</span> <span class="n">title</span><span class="p">,</span> <span class="nf">COUNT</span><span class="p">(</span><span class="n">title</span><span class="p">)</span> <span class="k">AS</span> <span class="n">num_found</span> </span><span id="L-2"><a name="L-2"></a><span class="k">FROM</span> <span class="n">articles</span> </span><span id="L-3"><a name="L-3"></a><span class="k">GROUP</span> <span class="k">BY</span> <span class="n">title</span> </span><span id="L-4"><a name="L-4"></a><span class="k">HAVING</span> <span class="n">num_found</span> <span class="o">&gt;</span> <span class="mi">1</span> </span><span id="L-5"><a name="L-5"></a><span class="k">ORDER</span> <span class="k">BY</span> <span class="n">num_found</span> <span class="k">DESC</span><span class="p">;</span> </span></pre></div> </td></tr></table>
count, group, mysql, select