This whole process is to join duplicate user accounts that have been created. If a user changes their email address, instead of updating it in their profile, they will often just create a whole new account. Then they have searches they have conducted under the old account and new account. I go into my backend admin tool and find these duplicate accounts. So I check the creation dates and last login dates to determine which account to keep and which to merge. Sometimes the newest created account is not always the best to save because their login dates show the older account was actually logged into most recently. Yeah, I can't explain why they do that...weird eh?
Once I figure out which account to keep as the main one, I grab the user ID from the other one and plug it into my query. It then goes through several tables transferring the author of the searches, favorites, leads, etc. to the account I want to keep. I'm getting this error message because some of these people are searching on various keywords, like "anger" from BOTH of their accounts.
To answer your question, when joining these duplicate accounts, I would like it to notice a keyword already exists, skip it, then move onto the other keywords stored in the searches table. Right now, when it comes across a duplicate, it fails the whole script and the rest of the search terms do not get merged.
As far as how searching comes into play, the website tracks everything the user looks for. So if they don't find any testimonials on "anger", the website will email them in the future if a testimonial is posted that matches their keyword. It's all about creating an incentive to keep the users coming back to the site over and over again. So far its working great and there are over 15,000 users.
I hope this helps Rudy. Let me know what else you need.