oracle

Any idea,
I accidentally added records twice in a oracle table.
Any idea how can I remove duplicate records in a table easily?
Thanks.
Al
ALad2005Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

slightwv (䄆 Netminder) Commented:
If it doesn't matter which one you keep, the correlated subquery is a good way:
delete from tab1 t1 where rowid > (
select min(rowid) from tab1 t2 where t1.col1=t2.col1 and t1.col2=t2.col2
)


There are several others.
0
Anil_LadCommented:
I used this, but no rows were deleted.
some of records have empty values , may be the compare might fail there?
Thanks.
Anil
0
slightwv (䄆 Netminder) Commented:
null values will cause a problem.

Try this:
delete from tab1 t1 where rowid > (
 select min(rowid) from tab1 t2 where
      (t1.col1=t2.col1 or (t1.col1 is null and t2.col1 is null))
      and
      (t1.col2=t2.col2 or (t1.col2 is null and t2.col2 is null))
 )
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
awking00Information Technology SpecialistCommented:
Is there a key field (or key fields) that make a record unique? If so,
delete from tab1 where rowid in
(select rowid from (select rowid, row_number() over (partition by key, order by key) rn from tab1)
 where rn > 1;
0
ALad2005Author Commented:
thank you guys.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Oracle Database

From novice to tech pro — start learning today.