turtleman8605 Posted June 2, 2008 Share Posted June 2, 2008 I am working on a script to clean out a bad database table of users that has multiple entries for each user (identified by email) I am trying to use SELECT DISTINCT (email), first_name, .... In other words, email is the only field that is necessarily unique and I want to keep only one row for each email address. How can I do this so that it allows for the other fields to be duplicates? Link to comment https://forums.phpfreaks.com/topic/108419-deletinh-rows-in-mysql/ Share on other sites More sharing options...
metrostars Posted June 2, 2008 Share Posted June 2, 2008 How do you know which row is the correct one to keep then? This makes all the difference in writing a query? Link to comment https://forums.phpfreaks.com/topic/108419-deletinh-rows-in-mysql/#findComment-555903 Share on other sites More sharing options...
DarkWater Posted June 2, 2008 Share Posted June 2, 2008 Please elaborate a bit more. Link to comment https://forums.phpfreaks.com/topic/108419-deletinh-rows-in-mysql/#findComment-555905 Share on other sites More sharing options...
turtleman8605 Posted June 3, 2008 Author Share Posted June 3, 2008 OK, sorry about the lack of details. The way that I want to choose which one to keep is by a the `last_login` field. If the user has never logged in it will show 00-00-00 00:00:00 (Datetime field). If it is anything other than that, then the user has logged in using this row's information and it is possible that they have changed data, so I don't want to lose this one. However, if all `last_login` fields are 0, then it doesn't matter. The duplicate rows however do have unique `id` fields. Link to comment https://forums.phpfreaks.com/topic/108419-deletinh-rows-in-mysql/#findComment-556112 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.