{"id":171,"date":"2014-12-02T22:56:36","date_gmt":"2014-12-02T22:56:36","guid":{"rendered":"http:\/\/baselines.com\/blog\/?p=171"},"modified":"2014-12-02T22:56:36","modified_gmt":"2014-12-02T22:56:36","slug":"to-find-duplicates-in-a-mysql-field","status":"publish","type":"post","link":"https:\/\/baselines.com\/blog\/?p=171","title":{"rendered":"To find duplicates in a mysql field"},"content":{"rendered":"<p>Do a <code><span style=\"font-family: Courier New; font-size: medium;\">SELECT<\/span><\/code> with a <code><span style=\"font-family: Courier New; font-size: medium;\">GROUP BY<\/span><\/code> clause. Let&#8217;s say <em>name<\/em> is the column you want to find duplicates in:<\/p>\n<pre class=\"lang-sql prettyprint prettyprinted\"><code><span style=\"font-family: Courier New;\"><span class=\"kwd\">SELECT<\/span><span class=\"pln\"> name<\/span><span class=\"pun\">,<\/span><span class=\"pln\"> COUNT<\/span><span class=\"pun\">(*)<\/span><span class=\"pln\"> c <\/span><span class=\"kwd\">FROM<\/span> <span class=\"kwd\">table<\/span> <span class=\"kwd\">GROUP<\/span> <span class=\"kwd\">BY<\/span><span class=\"pln\"> name <\/span><span class=\"kwd\">HAVING<\/span><span class=\"pln\"> c <\/span><span class=\"pun\">&gt;<\/span> <span class=\"lit\">1<\/span><span class=\"pun\">;<\/span><\/span><\/code><\/pre>\n<p>This will return a result with the <em>name<\/em> value in the first column, and a count of how many times that value appears in the second.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Do a SELECT with a GROUP BY clause. Let&#8217;s say name is the column you want to find duplicates in: SELECT name, COUNT(*) c FROM table GROUP BY name HAVING c &gt; 1; This will return a result with the name value in the first column, and a count of how many times that value [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-171","post","type-post","status-publish","format-standard","hentry","category-software-development"],"_links":{"self":[{"href":"https:\/\/baselines.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/171","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/baselines.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/baselines.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/baselines.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/baselines.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=171"}],"version-history":[{"count":1,"href":"https:\/\/baselines.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/171\/revisions"}],"predecessor-version":[{"id":172,"href":"https:\/\/baselines.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/171\/revisions\/172"}],"wp:attachment":[{"href":"https:\/\/baselines.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=171"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/baselines.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=171"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/baselines.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=171"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}