0% found this document useful (0 votes)
16 views9 pages

5 Ways To Delete Records in SQL

sql

Uploaded by

varam10
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views9 pages

5 Ways To Delete Records in SQL

sql

Uploaded by

varam10
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

12/4/2015

5waystodeleteduplicaterecordsOracle|sqlandplsql.com

5waystodeleteduplicaterecordsOracle
PostedonJanuary29,2013

InOracletherearemanywaystodeleteduplicaterecords.Notethatbelowexamplearedescribedtojustexplain
thedifferentpossibilities.
ConsidertheEMPtablewithbelowrows
createtableemp(
EMPNNOinteger,
EMPNAMEvarchar2(20),
SALARYnumber)
10Bill2000
11Bill2000
12Mark3000
12Mark3000
12Mark3000
13Tom4000
14Tom5000
15Susan5000
1.Usingrowid
SQL>deletefromemp
whererowidnotin
(selectmax(rowid)fromempgroupbyempno)
Thistechniquecanbeappliedtoalmostscenarios.Groupbyoperationshouldbeonthecolumnswhichidentify
theduplicates.
2.Usingselfjoin
SQL>deletefromempe1
whererowidnotin
(selectmax(rowid)fromempe2
wheree1.empno=e2.empno)

Follow

Follow
sqlandplsql.com
Get every new post delivered
to your Inbox.
Join 242 other followers
Enteryouremailaddress

3.Usingrow_number()

Signmeup
Build a website with WordPress.com

SQL>deletefromempwhererowidin
(
selectridfrom
(

http://sqlandplsql.com/2013/01/29/5waystodeleteduplicaterecordsoracle/

1/9

12/4/2015

5waystodeleteduplicaterecordsOracle|sqlandplsql.com

selectrowidrid,
row_number()over(partitionbyempnoorderbyempno)rn
fromemp
)
wherern>1
)
Thisisanotherefficientwaytodeleteduplicates
4.Usingdense_rank()
SQL>deletefromempwhererowidin
(
selectridfrom
(
selectrowidrid,
dense_rank()over(partitionbyempnoorderbyrowid)rn
fromemp
)
wherern>1
)
Hereyoucanusebothrank()anddens_rank()sincebothwillgiveuniquerecordswhenorderbyrowid.
5.Usinggroupby
ConsidertheEMPtablewithbelowrows
10Bill2000
11Bill2000
12Mark3000
13Mark3000
SQL>deletefromempwhere
(empno,empname,salary)in
(
selectmax(empno),empname,salaryfromemp
groupbyempname,salary
)
Thistechniqueisonlyapplicableinfewscenarios.
Alwaystakeextracautionwhiledeletingrecords.
1.Firstidentifytheduplicatesusingselect.

http://sqlandplsql.com/2013/01/29/5waystodeleteduplicaterecordsoracle/

2/9

12/4/2015

5waystodeleteduplicaterecordsOracle|sqlandplsql.com

2.Doubleverifythoseareactualduplicatesornot
3.Takebackupifnecessary
4.Applycommitonlyifyouaresure.
Didyoufindabovepostuseful?Yourcommentsarehighlyvaluable.
About these ads

Sharethis:

Twitter

Facebook

21

Google

Like
2bloggerslikethis.

Related

MergeOracle
In"Oracle"

Nthhighestsalary
In"Oracle"

OracleMAXfunction
In"Oracle"

Aboutsqlandplsql
TolearnmoreabouttheOracle,SQL,PLSQL,PerformanceTuning,DatabaseModeling,Ubuntu,MySQLetc.Suggestions,
comments,feedbacksandreferralsarehighlyappreciated.
Viewallpostsbysqlandplsql

ThisentrywaspostedinOracleandtaggeddeleteduplicate,deleteduplicaterows,deleteduplicates,DeleteduplicatesOracle,EliminateduplicateOracle,removeduplicate.
Bookmarkthepermalink.

40Responsesto5waystodeleteduplicaterecordsOracle
mcorreasays:
April22,2013at1:57am

Thanks.Itsveryusefull.
Reply

thejusays:
http://sqlandplsql.com/2013/01/29/5waystodeleteduplicaterecordsoracle/

3/9

12/4/2015

5waystodeleteduplicaterecordsOracle|sqlandplsql.com
June15,2013at3:03am

super.urhighlytalented..
Reply

sqlandplsqlsays:
June15,2013at1:44pm

Thatsfunny.Anywaythanks

rekhasays:
September22,2014at10:25pm

Veryverythanksitsveryusefull.

hisadorerussell.mihanblog.comsays:
May3,2014at1:01am

Iconstantlysentmyhallfanhotoreadthiswebsitescontentallthhetime
al ngwithacupofcoffee.
Reply

sqlandplsqlsays:
May13,2014at11:56pm

Thanks
Reply

balramreddysays:
May14,2014at6:26pm

veryusefulthanksalot..
Reply

sqlandplsqlsays:
May14,2014at8:10pm

Youarewelcome.
Reply

ganaysasays:
September16,2014at6:25am

Thankyou,veryusefulfunctionpartition.
Reply

http://sqlandplsql.com/2013/01/29/5waystodeleteduplicaterecordsoracle/

4/9

12/4/2015

5waystodeleteduplicaterecordsOracle|sqlandplsql.com

Visvasays:
September24,2014at10:44pm

Allareeasiestmethods..thanksalotIgotthebetterresultwhenIusethe1stMethod..Thanksagain.
Reply

sqlandplsqlsays:
September25,2014at6:49am

Thanksforthecomment
Reply

raghusays:
October12,2014at11:26am

veryusefull
Reply

vvsays:
October17,2014at8:36am

Goodone
Reply

sqlandplsqlsays:
October17,2014at8:42am

Thanks
Reply

Mahendrasays:
October21,2014at2:31am

goodjob..
Reply

seshusays:
November4,2014at10:23am

Thanksbrourreallygreat
Reply

srinisays:
November24,2014at2:22am

thanks
http://sqlandplsql.com/2013/01/29/5waystodeleteduplicaterecordsoracle/

5/9

12/4/2015

5waystodeleteduplicaterecordsOracle|sqlandplsql.com
Reply

mamboosays:
December7,2014at8:37am

veryusefulurtext
Reply

srikanthsays:
December24,2014at7:44am

deletefromxyzwhererowidnotin(
selectmax(rowid)fromxyzgroupbyempno)
Reply

srikanthsays:
December24,2014at7:46am

isitcorrectwaytoeliminateduplicates.,,Itriedforeliminationofcompleterowduplicateinatable
Reply

Rajasekar_Ariyalursays:
January22,2015at1:20am

Yeah!itisveryusefullsessionforme!thankyou.!!!
Reply

sqlandplsqlsays:
February20,2015at8:04am

Thanks
Reply

Kishansays:
March11,2015at11:08am

Whycantweuserownuminplaceofrowidintheveryfirstsolution.
Reply

pratapsays:
April21,2015at2:59am

Thatshelpfullformeandotherlearner..
Reply

http://sqlandplsql.com/2013/01/29/5waystodeleteduplicaterecordsoracle/

6/9

12/4/2015

5waystodeleteduplicaterecordsOracle|sqlandplsql.com

gireeshsays:
May16,2015at12:46am

awesomethanku
Reply

Kiruthigasays:
May20,2015at4:17am

Itsreallyusefull
thanks
Reply

Muraliisays:
May21,2015at4:28am

Canuplzexplaintheselfjoinmethodofremovingduplicaterowsfromatable.
Reply

muralitechsays:
May21,2015at4:30am

Canuexplainselfjoinmethodofremovingduplicatevalues
Reply

LEENAsays:
May22,2015at6:09am

CANUPLSSHARE,,howtodeleteduplicaterowsfromtableinoracle8i
Reply

sqlandplsqlsays:
May22,2015at7:22am

Allmostallabovewilleorkin8itoo
Reply

Rmrsays:
June15,2015at9:01pm

Goodwork.Keepgoing.
Reply

pawansays:
July3,2015at10:40pm

whenideleteusingrowiditwasnotworking.
http://sqlandplsql.com/2013/01/29/5waystodeleteduplicaterecordsoracle/

7/9

12/4/2015

5waystodeleteduplicaterecordsOracle|sqlandplsql.com
Reply

srikanthsays:
July4,2015at4:37am

HI,byreadingthis,ihaveclearedmyconfsonwhcihstorcheringsincelasti.5years
Reply

DThotasays:
September2,2015at9:59am

Thanksitisveryusefulcanwehavemorequerieslikethis..?
Reply

sqlandplsqlsays:
September2,2015at11:33pm

Thanks
Reply

venkataramanasays:
September2,2015at11:27am

veryuseful
Reply

sqlandplsqlsays:
September2,2015at11:33pm

Thanks
Reply

Sunnysays:
October26,2015at11:59pm

Excellent..verymuchuseful
Reply

sqlandplsqlsays:
October27,2015at12:16am

Thanks
Reply

bhaskarsharmasays:
http://sqlandplsql.com/2013/01/29/5waystodeleteduplicaterecordsoracle/

8/9

12/4/2015

5waystodeleteduplicaterecordsOracle|sqlandplsql.com
October27,2015at11:45am

DeletefromemployeeawhereROWID>
(selectmin(ROWID)fromemployeebwherea,eid=b,eid)
Ithinkitisthemosteasywaytodeletethenewerrecordsfromtable.
#stayhappykeepcoding
Reply

sqlandplsql.com
TheTwentyTenTheme.

BlogatWordPress.com.

http://sqlandplsql.com/2013/01/29/5waystodeleteduplicaterecordsoracle/

9/9

You might also like