## How to delete users with no order history through phpmyadmin sql?

Question

I have a wordpress ecommerce website which I have begun to update after not touching it for over a year. The first thing I did was implement reCaptcha into all inquiry and contact forms to reduce the amount of spam that is sent to my business’ inbox. I have also got it working for login and user account creation, to hopefully reduce the amount of bot user accounts registering on my website.

I think I am in a good place to now to tackle the users side of this cleanup, which I have roughly 14,000 in my database. Of these users, there is probably only ~100-200 that have actually placed orders on my ecommerce website. I have been searching for a way to delete users with no order history, and I came across this post: https://wordpress.org/support/topic/how-do-i-delete-customers-with-no-orders/

Under phpmyadmin, I have navigated to SQL tab to run a query, but am not having success with the code provided by the above link. Here is a screenshot of what my SQL window looks like when selecting the wp_tom2users database. https://ibb.co/8488Zyk

If I try to hit update, without making any changes, I get this https://ibb.co/LrJcBmF
Same goes for if I try and paste the below code into the textbox and hit update.

SELECT * from wp_tom2users where wp_tom2users.ID not in (
SELECT meta_value FROM wp_tom2postmeta WHERE meta_key = '_customer_user'
) AND wp_tom2users.ID not in (
select distinct(post_author) from wp_tom2posts
)


I was hoping someone could help me with this, as I would prefer to leave the accounts with order history rather than bulk delete all users. I also want to mention, I have three users with administrator privileges which I would like to prevent from deleting as well.

Thank you for taking the time to read the essay I typed into my issue.

0
3 years 2019-10-22T13:08:30-05:00 0 Answers 110 views 0