Is there anyway I can erase all the duplicate entries from a certain table (users
)? Here is a sample of the type of entries I have. I must say the table users
consists of 3 fields, ID
, user
, and pass
.
mysql_query("DELETE FROM users WHERE ???") or die(mysql_error());
randomtest
randomtest
randomtest
nextfile
baby
randomtest
dog
anothertest
randomtest
baby
nextfile
dog
anothertest
randomtest
randomtest
I want to be able to find the duplicate entries, and then delete all of the duplicates, and leave one.
You can do it with three sqls:
You can solve it with only one query.
If your table has the following structure:
you could do something like that (this will delete all duplicate users based on username with and ID greater than the smaller ID for that username):
It works and I've already use something similar to delete duplicates.