Forum Moderators: coopster

Message Too Old, No Replies

Delete Duplicate row from database

Delete Duplicate row from database

         

vivek avasthi

6:09 am on Jun 28, 2006 (gmt 0)

10+ Year Member



How can i delete duplicate row from a database ..

i have a database with email and unique ID now i want to delete all duplicate emails from database ..

omoutop

6:40 am on Jun 28, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



One easy way (if you dont mind losing the id's) is:

- select email from table
- construct array of ALL emails
- use array_unique()
- delete db
- insert array elements into db

Scally_Ally

10:43 am on Jun 28, 2006 (gmt 0)

10+ Year Member



dont know what database you are using but an sql statement something like

delete from myTable
where (field1, field2)
not in
( select distinct(field1), field2
from myTable);

should do the trick

coopster

2:45 pm on Jun 28, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Sounds like you have your table setup incorrectly if you truly don't want duplicate email columns in there. You may want to either add the email column to your PRIMARY KEY definition or use a UNIQUE index on the column.

coopster

6:25 pm on Jul 1, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I also forgot to mention that before you do any type of updating such as this it is a very wise idea to make a backup copy of the file you will be mass updating.

Some additional discussions that may be of interest:
Select duplicate values [webmasterworld.com]
Remove duplicate database listings with PHPmyAdmin [webmasterworld.com]