473,416 Members | 1,609 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,416 software developers and data experts.

Duplicate Records

Stang02GT
1,208 Expert 1GB
Somehow i got a duplicate recorded into one of my tables.

Is there any way I can edit them, or will I have to delete both of the records and re-insert the correct records?
May 9 '08 #1
3 2201
debasisdas
8,127 Expert 4TB
try to use this sample code for reference
Expand|Select|Wrap|Line Numbers
  1. Delete from emp e 
  2. where rowid>(select min(rowid) from emp 
  3. where e.empno=empno)
May 12 '08 #2
amitpatel66
2,367 Expert 2GB
you can try this as well:

Expand|Select|Wrap|Line Numbers
  1.  
  2. delete from table_name where ROWID NOT IN (SELECT MAX(rowID) FROM table_name group by empno)
  3.  
  4.  
This will delete older records
May 13 '08 #3
r035198x
13,262 8TB
Somehow i got a duplicate recorded into one of my tables.

Is there any way I can edit them, or will I have to delete both of the records and re-insert the correct records?
Elaborating a bit on the replies given so far. The important things to note when trying to get rid of duplicate records are :


  • Back up first. Deleting records can cause several unprintable sounds to be uttered by the user/DBA who has just executed it.
  • Define duplicate. A duplicate is only identifiable if the uniqueness attributes have been well defined. This is important especially where multiple columns constitute the uniqueness attributes set.
  • A delete statement which also works for multiple uniqueness columns is :
Expand|Select|Wrap|Line Numbers
  1. DELETE FROM table_name
  2. WHERE rowid NOT IN
  3. (SELECT MIN(rowid)
  4. FROM table_name
  5. GROUP BY col1, col2, col3... ;
  6.  
Here col1, col2, e.t.c are the uniqueness columns.rowid is a special built in oracle "column" (pseudo-column) which uniquely identifies each row in a table. So every Oracle row has got it.
Note that rowid should not be used as part of the data of a row because even though it is unique, it changes every time you do EXP,IMP or in indexed and partitioned tables.


The inner select retrieves all the duplicates (as defined by the uniqueness attributes col1,col2, e.tc).
The delete then deletes all of them except the one with the least rowid.
  • Usually your table design should be structured in such a way that duplicates should not be possible. However, sometimes ghosts fly in the DB e.t.c. It's important though to recheck your table design everytime you see unintended duplicates.
Jun 3 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Gary Lundquest | last post by:
It appears to me that MySQL version 4 returns an error messge when doing an Insert that results in duplicate entries. Version 3 did NOT return an error - it dropped the duplicate entries and ran...
2
by: ms | last post by:
Access 2000: I am trying to delete duplicate records imported to a staging table leaving one of the duplicates to be imported into the live table. A unique record is based on a composite key of 3...
4
by: KT | last post by:
Is there any one click solution that would do the trick? I would like to create a button, so the person who maintains the database can perform clean up work to delete duplicate records which...
2
by: Carroll | last post by:
I'm looking for a way in SQL to find duplicate records in a single table, that are the same based on 3 columns, regardless of what is in the other columns in the duplicate records. I would like to...
0
by: B.N.Prabhu | last post by:
Hi, I have a DataTable with several rows. Its having 20 Columns. when i click the Insert button then i have to check the Database Rows. Whether these new rows are already available in the...
2
by: nethravathy | last post by:
Hi, The following table namely elcbtripselect contains 5147 records.I want to know wether this table contains duplicate records or not. I tried with following query 1)SELECT...
4
by: Thomas Arthur Seidel | last post by:
Hello to all, I have a small or big problem with a customer data base, where during a change of system we might have created duplicate records. This should be easy to find, you might think, but,...
2
by: nomvula | last post by:
hi guys i need some help to duplicate records on my form datasheet: here's the example of my form results: ClientLookup DateCaptured ForecastDate Description ForecastQuantity Forecast Actual UJ...
6
by: Dilip1983 | last post by:
Hi All, I want to delete duplicate records from a large table. There is one index(INDEX_U1) on 4 columns(col1,col2,col3,col4) which is in unusable state. First of all when i tried to rebuild...
1
by: xraive | last post by:
I have a problem with this. Currently I am trying Allen's code and i am not successful. Current Design Table1 (Main Form) TravelID (PK) ApprovedBY EntreredBy BudgetCode ExpenseCode
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.