andyh2 Posted December 21, 2008 Share Posted December 21, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/137946-removing-duplicate-rows/ Share on other sites More sharing options...
xtopolis Posted December 21, 2008 Share Posted December 21, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/137946-removing-duplicate-rows/#findComment-721015 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.