|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| ||||||||||||||||||||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
[MySQL 5] Finding and deleting duplicate entries in a large database table
Hi everyone!
I have the following problem. A large database which through some error, now contains a high number of duplicate entries within one of the columns. Now normally I would simply do things by hand, deleting the duplicate entries myself. However in this particular case, the database contains thousands of entries within this one table alone. Far more than I could ever possibly fix by hand. So I was wondering if there is a query, or method or piece of software which could be used to find and select just those rows which have duplicates within one of the columns, and if possible, delete one row of each duplicate (doesn't matter which is saved and which is removed as both are exactly the same, so long as one of the copies remains intact). The following may help Primary key = id Object_id = numerical (will be duplicated also in many cases) X_position = numerical (this is the one containing duplicates) Z_position = numerical Y_position = numerical I'm still pretty new at the database thing, and ended up having to do this because the person responsible kept passing the buck. I'm not afraid to get my hands dirty and delving in there, because I find all this really interesting. But I am a little out of my depth when it comes to something like this, and I don't entirely know what I'm doing. But as it does need doing, I'm hoping someone can help me out, and I didn't really know where else to ask. To further explain what's happening. The table is used to populate a map with instances of various 3D objects (Object_id), and works as intended. However the duplicates are causing second (and in some cases third) copies of the same instance to be placed at exactly the same location as many of the placed objects, with only very slight differences in orientation and positioning on the Z and Y axis', causing lots of clipping errors, extra work on the engine and visually it looks terrible. It's unprofessional and can't be left like that. Last edited by Ashberry : August 11th, 2009 at 08:49 AM. |
|
#2
|
||||
|
||||
|
Assuming this is MySQL
Hmm - maybe to find out what values have more then one entry - use a count with a group by Code:
SELECT value, if(count(*) > 1, 'Yes', '') FROM table GROUP BY value From there you can delete by hand or write a script to do it for you based on the results - maybe with a stored procedure or the lang of your choice Make sense?
__________________
life is a game.... Have fun ----------------------------- http://www.phpwomen.org strength in unity PHPCommunity IRC #phpc on freenode |
![]() |
| Viewing: Codewalkers Forums > Other Technologies > Database Help > Finding and deleting duplicate entries in a large database table |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|