Jump to content

Removing Duplicate Rows


andyh2

Recommended Posts

Hello all. I have a PHP script that is run every 5 minutes by cron, goes into a flash game, and grabs all of the users that are on a few certain servers and inputs their name, user ID, and some other data that isn't relevant to what I'm wondering about into a table. Currently, whenever the same user is found it just makes a new row for the user, and whenever the user is looked up from the web interface for this table, it uses the newest data. This obviously isn't very efficient, as it usually makes about one thousand rows whenever it runs the script. What I'm looking for is a way to look for duplicates of a username, then delete all of the duplicate rows with that username in it EXCEPT for the newest one. This would preferably be run by a cron job. Now, I'm not very savvy with MySQL so I don't know how to do this. If anyone has any guidance on how I can do this, please reply! :)

 

Thanks,

 

Andy

 

PS: my mysql server version is: 5.0.51a

Link to comment
https://forums.phpfreaks.com/topic/137946-removing-duplicate-rows/
Share on other sites

That really depends.  Can the same username be used on multiple servers, or is the username unique?

 

It seems like you're saying it's unique across the servers though.  You could have it do a:

INSERT ... ON DUPLICATE KEY UPDATE

 

It's kinda hard to tell without seeing your structures and knowing what data you are pulling.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.