Register and join over 40,000 other developers!
Recent Topics
-
The Game You Are Waiting For?
WendellHarper - Dec 06 2020 01:21 PM
-
Quora and Reddit Backlinks
WendellHarper - Dec 06 2020 01:14 PM
-
Delete account
pindo - Jul 23 2020 01:33 AM
-
Print specific values from dictionary with a specific key name
Siten0308 - Jun 20 2019 01:43 PM
-
Learn algorithms and programming concepts
johnnylo - Apr 23 2019 07:49 AM
Recent Blog Entries
Recent Status Updates
Popular Tags
- networking
- Managed C++
- stream
- console
- database
- authentication
- Visual Basic 4 / 5 / 6
- session
- Connection
- asp.net
- import
- syntax
- hardware
- html5
- array
- mysql
- java
- php
- c++
- string
- C#
- html
- loop
- timer
- jquery
- ajax
- javascript
- programming
- android
- css
- assembly
- c
- form
- vb.net
- xml
- linked list
- login
- encryption
- pseudocode
- calculator
- sql
- python
- setup
- help
- game
- combobox
- binary
- hello world
- grid
- innerHTML

How to delete duplicate entries in a table ?
Started by evk_87, Sep 07 2008 08:02 PM
12 replies to this topic
#1
Posted 07 September 2008 - 08:02 PM
In oracle 9i ........How to delete duplicate entries in a table ?
if suppose in a table named office, one or more entry(row) is repeated more then twice or minimum twice.
I need a query to delete the multiple entries ....
Note:
--->No constraints applied on the table.
--->No Primary Key
--->You cannot create any object....that is no view or a duplicate table can be created
Plz help !!!
if suppose in a table named office, one or more entry(row) is repeated more then twice or minimum twice.
I need a query to delete the multiple entries ....
Note:
--->No constraints applied on the table.
--->No Primary Key
--->You cannot create any object....that is no view or a duplicate table can be created
Plz help !!!
#2
Posted 08 September 2008 - 08:19 AM
You may need to delete all duplicates and then reinsert a single copy of the duplicated data.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog
My MineCraft server site: http://banishedwings.enjin.com/
#3
Posted 08 September 2008 - 09:24 AM
to read out all unique records, this should help
but that is just one small part of the problem. as he don't have any creation rights
I guess he can't create temporary tables either, if he could, this would be much easier
now, I guess the simplest way is to export the table contents to somewhere else
or at least the unique records, then delete everything and after everything import the unique records.
one more thig is, does the records have an auto increment field, then a lot might be so much different and difficult, as those id's might need to be preserved.
select distinct * from mytable
but that is just one small part of the problem. as he don't have any creation rights
I guess he can't create temporary tables either, if he could, this would be much easier
now, I guess the simplest way is to export the table contents to somewhere else
or at least the unique records, then delete everything and after everything import the unique records.
one more thig is, does the records have an auto increment field, then a lot might be so much different and difficult, as those id's might need to be preserved.
#4
Posted 13 September 2008 - 10:15 PM
If you want to delete duplicate row's find any common column between them and delete it, for Example
DELETE FROM t1 WHERE c1='a common phrase between duplicate columns';
another than that i assume if your rows are being duplicated that ur not using a unique constraint or that your using an automatically generated unique column so try having a composite constraint as it might nullify the possibility of having duplicate rows. other than that dnt really know of any method that is easier to delete duplicate rows expect for manually deleting them.
DELETE FROM t1 WHERE c1='a common phrase between duplicate columns';
another than that i assume if your rows are being duplicated that ur not using a unique constraint or that your using an automatically generated unique column so try having a composite constraint as it might nullify the possibility of having duplicate rows. other than that dnt really know of any method that is easier to delete duplicate rows expect for manually deleting them.
#5
Posted 14 September 2008 - 03:00 AM
Well, It's not that simple, what if different users enters the same info many times, unaware of each other into say a common address book? it's hard to prevent, and then you need to sort these out rather easy, withouot picking by hand etc.
it's dangerous to do a "delete from" on a live database like that when doing such hunting, especially when you have no create rights and can't backup information within the db. I suggest the export-cleaning-reimport version rather than working directly in the live db in this case, just for safety reasons.
it's dangerous to do a "delete from" on a live database like that when doing such hunting, especially when you have no create rights and can't backup information within the db. I suggest the export-cleaning-reimport version rather than working directly in the live db in this case, just for safety reasons.
#6
Posted 14 September 2008 - 10:36 AM
Also, you really need to create some primary keys to prevent this sort of thing in the future. At the very least, use a GUID so you have SOMETHING distinct.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog
My MineCraft server site: http://banishedwings.enjin.com/
#7
Posted 14 September 2008 - 08:32 PM
A common address book can be repeated but things such as ID number should exist as a a primary key which cant be repeated, or a unique key, to prevent data from being duplicated, or a database trigger which disallows the same row to be repeated.
And dnt really think its a live database and even if it was, what good it is if it has duplicated records, if the data is not really important i suggest creating a new one with Constraints, if not there's no other why i know off expect to back the data and delete them using the For Update in Oracle
And dnt really think its a live database and even if it was, what good it is if it has duplicated records, if the data is not really important i suggest creating a new one with Constraints, if not there's no other why i know off expect to back the data and delete them using the For Update in Oracle
#8
Posted 15 September 2008 - 03:53 AM
I can see that almost everyone has missed out a very special thing that the author of this thread stated:
so, all your suggestion of rearranging the table is totally useless in this case, as it's not his system and has not much rights to the database
don't make your ideas so easily based as it isn't so easy as you tell as "just make sure there is a primary key" and similar, as he can't change the DB structure! Be a little bit innovative instead and figure out how you actually help this guy??
Note:
--->No constraints applied on the table.
--->No Primary Key
--->You cannot create any object....that is no view or a duplicate table can be created
so, all your suggestion of rearranging the table is totally useless in this case, as it's not his system and has not much rights to the database
don't make your ideas so easily based as it isn't so easy as you tell as "just make sure there is a primary key" and similar, as he can't change the DB structure! Be a little bit innovative instead and figure out how you actually help this guy??
#9
Posted 15 September 2008 - 05:25 AM
ok we'll try to be a bit more innovative lol
"SELECT DISTINCT * FROM YourTable"
Execute this query and then export the data on an excel sheet the data which is outputed after executing the query.
After exporting it Truncate the table and i believe that u dnt have 2 be an administrator to use this command.
"TRUNCATE TABLE yourTable" this is gna delete all of the rows in the table but well keep the structure as it is.
and then import what you exported to the truncated table.
in this way you'll be able to delete all of the duplicated data and replace them with the original.
Regards
"SELECT DISTINCT * FROM YourTable"
Execute this query and then export the data on an excel sheet the data which is outputed after executing the query.
After exporting it Truncate the table and i believe that u dnt have 2 be an administrator to use this command.
"TRUNCATE TABLE yourTable" this is gna delete all of the rows in the table but well keep the structure as it is.
and then import what you exported to the truncated table.
in this way you'll be able to delete all of the duplicated data and replace them with the original.
Regards
#10
Posted 15 September 2008 - 06:21 AM
and if you can't use truncte, you would still be able to use "delete from table;" which cleans the table, but doesn't reset any counters and stuff...
#11
Posted 30 October 2008 - 09:35 PM
use DISTINCT
#12
Posted 31 October 2008 - 02:50 AM
hmm.. it's not just that easy, if you delete with DISTINCT, in my world, you would have the posts that were to be deleted left...
by the way, why are you re-opening so many several month old issues like this and just bumping threads?? it's not what to call a good forum-netiquette... and double-posting like you never had a forum expericence in your life.. get real please...
by the way, why are you re-opening so many several month old issues like this and just bumping threads?? it's not what to call a good forum-netiquette... and double-posting like you never had a forum expericence in your life.. get real please...
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download