I'm working on a social network web application, and i got a situation where i need to resend reminder emails to users who haven't activated their emails. The problem is when i investigated the DB i found that many emails are duplicated (there was no validation on the email uniqueness apparently. So what i need to do know is to retrieve these fields from the db the username, email activation code, email, so that i can resend the activation emails, and for the case of the duplicated emails i need to return only one of them (i.e if i have user john with email [email protected] and user john1 with email [email protected] too, i want to retrieve only on of these johns no matter john1 or two) so i thought of tailing the sql query by (Group By Email). The thing is that i can't select other fields that are not in the group by clause. the solution that i have here is one that i don't like; i created a List and every time when i need to send an email to a user i iterate all over the entire list to make sure that this email is not existing, if it's not there, i send to it, and then add the email to the list. Something like the following: if(!EmailIsInList(email)){ SendActivationEmail(email); AddEmailToList(email) } else { DoNotSend); }
Actually i got the problem solved this way, still i don't like my solution. Any ideas?