{"id":384,"date":"2012-05-10T10:23:40","date_gmt":"2012-05-10T07:23:40","guid":{"rendered":"http:\/\/fatihacar.com\/blog\/?p=384"},"modified":"2020-06-22T08:50:56","modified_gmt":"2020-06-22T05:50:56","slug":"delete-duplicate-rows-without-all-records-in-oracle","status":"publish","type":"post","link":"https:\/\/www.fatihacar.com\/blog\/delete-duplicate-rows-without-all-records-in-oracle\/","title":{"rendered":"Delete Duplicate Rows Without All Records in Oracle"},"content":{"rendered":"<p>If you want to delete duplicate rows but not all rows in table, you can use a procedure.  For example, you have 10 duplicate rows and you want to delete 9 rows, then you can use procedure to delete process. For instance, you have a table as tmp_table. tmp_table&#8217;s columns are id,name,surname,city,phone. You want to delete duplicate for name,surname,city. You can use below procedure for this process.<\/p>\n<p><strong>Delete Duplicate Rows Procedure<\/strong><\/p>\n<blockquote><p>\nCREATE OR REPLACE PROCEDURE deleteduplicate<br \/>\nIS<br \/>\nBEGIN<br \/>\nFOR duplicates IN ( SELECT max(id) id, name, surname, city<br \/>\nFROM tmp_table GROUP BY name,surname,city<br \/>\nHAVING count(*)>1)<\/p>\n<p>LOOP<br \/>\nDELETE FROM tmp_table t<br \/>\nWHERE t.name = duplicates.name<br \/>\nAND t.surname = duplicates.surname<br \/>\nAND t.city = duplicates.city<br \/>\nAND t.id != duplicates.id;<br \/>\nEND LOOP;<br \/>\nCOMMIT;<br \/>\nEND;\n<\/p><\/blockquote>\n<p>to delete only old dates one you can use below script. This script for me :)<\/p>\n<blockquote><p>\ndelete from tmp_table where id in(<br \/>\nselect a.id from tmp_table a,tmp_table b<br \/>\nwhere a.tarih < b.tarih\nand a.serino = b.serino\nand a.serino in (select serino from tmp_table\nwhere group by serino having count(1)>1));\n<\/p><\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>If you want to delete duplicate rows but not all rows in table, you can use a procedure. For example, you have 10 duplicate rows and you want to delete 9 rows, then you can use procedure to delete process. For instance, you have a table as tmp_table. tmp_table&#8217;s columns are id,name,surname,city,phone. You want to&#8230;<\/p>\n","protected":false},"author":37,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[9,12,6],"tags":[14,90,13],"class_list":["post-384","post","type-post","status-publish","format-standard","hentry","category-administration","category-oracle-procedure","category-oracle-sql","tag-database-administration","tag-oracle","tag-stored-procedure"],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p39NFI-6c","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.fatihacar.com\/blog\/wp-json\/wp\/v2\/posts\/384","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.fatihacar.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.fatihacar.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.fatihacar.com\/blog\/wp-json\/wp\/v2\/users\/37"}],"replies":[{"embeddable":true,"href":"https:\/\/www.fatihacar.com\/blog\/wp-json\/wp\/v2\/comments?post=384"}],"version-history":[{"count":6,"href":"https:\/\/www.fatihacar.com\/blog\/wp-json\/wp\/v2\/posts\/384\/revisions"}],"predecessor-version":[{"id":2776,"href":"https:\/\/www.fatihacar.com\/blog\/wp-json\/wp\/v2\/posts\/384\/revisions\/2776"}],"wp:attachment":[{"href":"https:\/\/www.fatihacar.com\/blog\/wp-json\/wp\/v2\/media?parent=384"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.fatihacar.com\/blog\/wp-json\/wp\/v2\/categories?post=384"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.fatihacar.com\/blog\/wp-json\/wp\/v2\/tags?post=384"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}