{"id":462,"date":"2010-02-08T12:02:09","date_gmt":"2010-02-08T12:02:09","guid":{"rendered":"http:\/\/kedar.nitty-witty.com\/?p=462"},"modified":"2014-06-24T18:04:43","modified_gmt":"2014-06-24T18:04:43","slug":"oracle-query-eliminate-duplicate-but-one-using-rowid","status":"publish","type":"post","link":"https:\/\/kedar.nitty-witty.com\/blog\/oracle-query-eliminate-duplicate-but-one-using-rowid","title":{"rendered":"Oracle query-eliminate duplicate but one using rowid"},"content":{"rendered":"<p>Yesterday a friend came across an oracle query problem:<\/p>\n<p>Consider below table:<\/p>\n<p><code>cid\tcname....\tcdata<br \/>\n1\tx\t\txxxx<br \/>\n1\tx\t\txxxx ..<br \/>\n2\txzzz\t\tfjnd<br \/>\n3\ta\t\tevddd<\/code><\/p>\n<p>Now the problem was cid is repeated and cdata column is having some extra characters but data is considered same (eg. xxxx &#038; xxxx..).<br \/>\nso when he does<br \/>\n<code>SELECT cid,cname....cdata FROM TABLENAME ....;<br \/>\n<\/code><br \/>\nHe kept on getting duplicated records which intern he wanted to have only one per duplicated cid.<br \/>\nIt&#8217;s not by the way of table structure but by the way of query he wanted to have results.<\/p>\n<p>I suggested him:<br \/>\n<code>SELECT cid,cname....cdata FROM TABLENAME GROUP BY cid;<br \/>\n<\/code><br \/>\nAs far as I know this works with MySQL, but it gave error as I came to know that I have to include all SELECTed variables in GROUP BY clause.<br \/>\nThis is Oracle \ud83d\ude42<\/p>\n<p>Well later I came back to my place and recollected something called ROWID of Oracle, may be that can help!!<\/p>\n<p>Then I created similar table in MySQL to &#8220;stimulate&#8221; Oracle rowID:<\/p>\n<p><code>rowId\tcid\tcname ....\tcdata<br \/>\n1\t1\tx\t\txxxx<br \/>\n2\t1\tx\t\txxxx ..<br \/>\n3\t2\txzzz\t\tfjnd<br \/>\n4\t3\ta\t\tevddd<\/code><\/p>\n<p>And finally I got the solution as:<\/p>\n<p>select cid,cname&#8230;.cdata from tablename where rowID in (select min(rowID) from tablename group by cid);<\/p>\n<p>So finally I decided to give it a try on Oracle and it worked \ud83d\ude42<\/p>\n<p><code>select * from TABLENAME WHERE rowid in (select min(rowid) from TABLENAME group by DUPLICATECOLUMN);<br \/>\n<\/code><\/p>\n","protected":false},"excerpt":{"rendered":"Yesterday a friend came across an oracle query problem: Consider below table: cid cname&#8230;. cdata 1 x xxxx 1 x xxxx .. 2 xzzz fjnd 3 a evddd Now the&hellip;\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[8,6],"tags":[247,94,248,426],"class_list":{"0":"post-462","1":"post","2":"type-post","3":"status-publish","4":"format-standard","6":"category-mysql","7":"category-technical","8":"tag-elliminatae-duplicate-in-oracle","9":"tag-query","10":"tag-rowid","11":"tag-technical"},"aioseo_notices":[],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/kedar.nitty-witty.com\/blog\/wp-json\/wp\/v2\/posts\/462","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kedar.nitty-witty.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kedar.nitty-witty.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kedar.nitty-witty.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kedar.nitty-witty.com\/blog\/wp-json\/wp\/v2\/comments?post=462"}],"version-history":[{"count":1,"href":"https:\/\/kedar.nitty-witty.com\/blog\/wp-json\/wp\/v2\/posts\/462\/revisions"}],"predecessor-version":[{"id":1598,"href":"https:\/\/kedar.nitty-witty.com\/blog\/wp-json\/wp\/v2\/posts\/462\/revisions\/1598"}],"wp:attachment":[{"href":"https:\/\/kedar.nitty-witty.com\/blog\/wp-json\/wp\/v2\/media?parent=462"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kedar.nitty-witty.com\/blog\/wp-json\/wp\/v2\/categories?post=462"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kedar.nitty-witty.com\/blog\/wp-json\/wp\/v2\/tags?post=462"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}