SQL query to merge users with same email

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Mr. Mikey
    Senior Member
    • Feb 2009
    • 187

    SQL query to merge users with same email

    I have several hundred users who have the same email address whom I want to merge together, I was wondering what the SQL query would be for it, I thought it could be something like;

    Code:
    UPDATE vb_user
    SET username = X
    WHERE email LIKE '%[email protected]%'
    but I think that would only work on one user, and I have several hundred, I'm looking for a way other than "Merge Users" in the admincp, as it would take hours. I'm not adverse to doing it manually, however if there is a quicker way, naturally I will take it.

    Again, I need to MERGE the users based on email address, the above query is most likely wrong because I couldn't find the SQL which merges the accounts.

    Edit, I've found the SQL to LIST users with the same email address;

    Code:
    SELECT username, email FROM vb_user GROUP BY email HAVING COUNT(email) > 1
    now how would I merge them? :/
    My Forums: The Geek District - Off Topic Hut
    My Blog: Mikeylicious
    Projects: Shorten URL's with kwn.me
  • Dean C
    Senior Member
    • Mar 2002
    • 4571
    • 3.5.x

    #2
    This is definitely not the approach you should follow. You certainly shouldn't be doing it via pure SQL due to the large amount of foreign keys which will reference the defunct user id's. A better way would be to look at the code behind the merge user action and write a script to do it in mass.
    Dean Clatworthy - Web Developer/Designer

    Comment

    • Mr. Mikey
      Senior Member
      • Feb 2009
      • 187

      #3
      The duplicate accounts all have 0 posts, so I don't have to worry about the defunct userid's referenced in posts.
      My Forums: The Geek District - Off Topic Hut
      My Blog: Mikeylicious
      Projects: Shorten URL's with kwn.me

      Comment

      widgetinstance 262 (Related Topics) skipped due to lack of content & hide_module_if_empty option.
      Working...