{"id":160,"date":"2015-04-23T10:17:35","date_gmt":"2015-04-23T14:17:35","guid":{"rendered":"http:\/\/salzlechner.com\/dev\/?p=160"},"modified":"2016-03-11T07:06:41","modified_gmt":"2016-03-11T12:06:41","slug":"sql-query-to-find-duplicate-values","status":"publish","type":"post","link":"http:\/\/salzlechner.com\/dev\/2015\/04\/23\/sql-query-to-find-duplicate-values\/","title":{"rendered":"SQL Query to find duplicate values"},"content":{"rendered":"<p>An easy way to find duplicate entries in a table<\/p>\n<pre class=\"lang:tsql decode:true\">SELECT DAY_PHONE, COUNT(DAY_PHONE)\r\nFROM CUST\r\nGROUP BY DAY_PHONE HAVING (COUNT(DAY_PHONE)&gt;1)\r\nORDER BY DAY_PHONE<\/pre>\n<p>The above will list the phone numbers that are at least twice in the table and also show the number of occurrences<\/p>\n<p>But often we need to show all the records containing the duplicate entries<\/p>\n<p>we can do that with the following query<\/p>\n<pre class=\"lang:default decode:true\">;with DUPES as\r\n(\r\nselect CUST.DAY_PHONE as PHONE\r\nfrom CUST\r\nwhere\r\n.. additional selection here ..\r\nGROUP by CUST.DAY_PHONE\r\nHAVING COUNT(*) &gt; 1\r\n)\r\nSELECT C.CODE, C.NAME, C.DAY_PHONE\r\nFROM DUPES\r\nINNER JOIN CUST as C\r\nON DUPES.PHONE = C.DAY_PHONE\r\nORDER BY DUPES.PHONE\r\n<\/pre>\n<p>the query above will list all records with phone numbers that exist at least twice in the table ordered by phone number<\/p>\n","protected":false},"excerpt":{"rendered":"<p>have a need to find duplicate entries such as phone numbers in a SQL table. This blog post will show you how to find them<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_et_pb_use_builder":"","_et_pb_old_content":"","_et_gb_content_width":"","ngg_post_thumbnail":0,"footnotes":""},"categories":[24],"tags":[],"class_list":["post-160","post","type-post","status-publish","format-standard","hentry","category-sql"],"_links":{"self":[{"href":"http:\/\/salzlechner.com\/dev\/wp-json\/wp\/v2\/posts\/160","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/salzlechner.com\/dev\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/salzlechner.com\/dev\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/salzlechner.com\/dev\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/salzlechner.com\/dev\/wp-json\/wp\/v2\/comments?post=160"}],"version-history":[{"count":3,"href":"http:\/\/salzlechner.com\/dev\/wp-json\/wp\/v2\/posts\/160\/revisions"}],"predecessor-version":[{"id":278,"href":"http:\/\/salzlechner.com\/dev\/wp-json\/wp\/v2\/posts\/160\/revisions\/278"}],"wp:attachment":[{"href":"http:\/\/salzlechner.com\/dev\/wp-json\/wp\/v2\/media?parent=160"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/salzlechner.com\/dev\/wp-json\/wp\/v2\/categories?post=160"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/salzlechner.com\/dev\/wp-json\/wp\/v2\/tags?post=160"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}