WP-Mix

A fresh mix of code snippets and tutorials

Find duplicate email addresses in WordPress

This tutorial explains how to find duplicate email addresses in your WordPress database. That way you can delete or modify as needed.

In WordPress, users can not change their username, but they can change their email address all day long. This and other factors means that you may end up with multiple/duplicate addresses in your database. To find them, execute the following query (via phpMyAdmin or whatever works for you):

SELECT user_email, COUNT(user_email) 
AS NumOccurrences
FROM wp_users
GROUP BY user_email
HAVING (COUNT(user_email) > 1)

Note that you may need to edit the wp_ string to match any custom prefix that you are using for your database tables.

That query will return any/all duplicate email addresses, so you can deal with them however you like (e.g., change ’em, delete ’em, etc.).

Bonus

SQL query for cleaning up any newline/return characters appended to email addresses:

UPDATE wp_users SET user_email = Replace(user_email, char(13), '');
UPDATE wp_users SET user_email = Replace(user_email, char(10), '');

Remember to always back up your database before making any changes :)

Learn more

Digging Into WordPressWordPress Themes In DepthWizard’s SQL Recipes for WordPress