{"id":197,"date":"2020-03-20T12:00:00","date_gmt":"2020-03-20T12:00:00","guid":{"rendered":"https:\/\/molecularsciences.org\/content\/?p=197"},"modified":"2024-02-08T08:57:37","modified_gmt":"2024-02-08T13:57:37","slug":"finding-duplicate-values-in-a-mysql-database","status":"publish","type":"post","link":"https:\/\/molecularsciences.org\/content\/finding-duplicate-values-in-a-mysql-database\/","title":{"rendered":"Finding duplicate values in a MySQL database"},"content":{"rendered":"\n<p>In the following query, we list all lastname held by 2 or more employees.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT lastname, COUNT(*) c FROM employees GROUP BY lastname HAVING c > 1;<\/code><\/pre>\n\n\n\n<p>If you want a value to be unique, you should add a unique constraint to the column. However, you would from time to time have to deal with a badly designed database. In such cases, this query will come in handy.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In the following query, we list all lastname held by 2 or more employees. If you want a value to be unique, you should add a unique constraint to the column. However, you would from time to time have to deal with a badly designed database. In such cases, this query will come in handy.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16,204],"tags":[14,27],"class_list":["post-197","post","type-post","status-publish","format-standard","hentry","category-database","category-mysql","tag-database","tag-mysql"],"_links":{"self":[{"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/posts\/197","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/comments?post=197"}],"version-history":[{"count":1,"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/posts\/197\/revisions"}],"predecessor-version":[{"id":198,"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/posts\/197\/revisions\/198"}],"wp:attachment":[{"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/media?parent=197"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/categories?post=197"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/tags?post=197"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}