{"id":67,"date":"2008-10-27T11:09:29","date_gmt":"2008-10-27T16:09:29","guid":{"rendered":"http:\/\/www.popmartian.com\/tipsntricks\/?p=67"},"modified":"2009-02-06T12:00:59","modified_gmt":"2009-02-06T17:00:59","slug":"sql-select-duplicate-rows-select-indistinct-rows","status":"publish","type":"post","link":"https:\/\/www.popmartian.com\/tipsntricks\/2008\/10\/27\/sql-select-duplicate-rows-select-indistinct-rows\/","title":{"rendered":"SQL: Select duplicate rows, select indistinct rows"},"content":{"rendered":"<p>Using SQL, MySQL or whatever your favorite database may be, we all know using <code>SELECT DISTINCT<\/code> will return unique values in case a value appears more than once in a table.<\/p>\n<p>How do you fine duplicates?  What if I want to know where the duplicates are?<\/p>\n<p>The trick is to use count() and compare it to an integer.<\/p>\n<p><code>SELECT count(*), locations.* FROM locations GROUP BY number HAVING COUNT(*) > 1<\/code><\/p>\n<p>That will select a count of unique instances of a value from a table called &#8220;locations&#8221;, group them by a field called &#8220;number&#8221; where the count is greater than 1.  In other words, it will return all the fields where there are more than one instance of the same value in the column &#8220;number&#8221;.<\/p>\n<blockquote><p>Did you find this post useful or have questions or comments?  Please let me know!<\/p><\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>Using SQL, MySQL or whatever your favorite database may be, we all know using SELECT DISTINCT will return unique values in case a value appears more than once in a table. How do you fine duplicates? What if I want &hellip; <a href=\"https:\/\/www.popmartian.com\/tipsntricks\/2008\/10\/27\/sql-select-duplicate-rows-select-indistinct-rows\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,53,41],"tags":[48,74,69],"class_list":["post-67","post","type-post","status-publish","format-standard","hentry","category-how-to-do-stuff","category-mysql","category-sql","tag-howto","tag-mysql","tag-sql"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.popmartian.com\/tipsntricks\/wp-json\/wp\/v2\/posts\/67","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.popmartian.com\/tipsntricks\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.popmartian.com\/tipsntricks\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.popmartian.com\/tipsntricks\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.popmartian.com\/tipsntricks\/wp-json\/wp\/v2\/comments?post=67"}],"version-history":[{"count":4,"href":"https:\/\/www.popmartian.com\/tipsntricks\/wp-json\/wp\/v2\/posts\/67\/revisions"}],"predecessor-version":[{"id":79,"href":"https:\/\/www.popmartian.com\/tipsntricks\/wp-json\/wp\/v2\/posts\/67\/revisions\/79"}],"wp:attachment":[{"href":"https:\/\/www.popmartian.com\/tipsntricks\/wp-json\/wp\/v2\/media?parent=67"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.popmartian.com\/tipsntricks\/wp-json\/wp\/v2\/categories?post=67"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.popmartian.com\/tipsntricks\/wp-json\/wp\/v2\/tags?post=67"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}