About this question
I have a list of invalid email addresses parsed in the following format;
There are roughly 1500 invalid addresses, and I need to remove them from my myBB users.
What SQL query can I run to remove the list from my database?
I have a list of invalid email addresses parsed in the following format;
There are roughly 1500 invalid addresses, and I need to remove them from my myBB users.
What SQL query can I run to remove the list from my database?
Log in to share your answer and help other learners.
Log in to answerBest Answer · By JanBask MS SQL Server Expert
Answered on Mar 14, 2023
If you have a main table like this CREATE TABLE users
(
id INT NOT NULL AUTO_INCREMENT,
email VARCHAR(255),
....
PRIMARY KEY (id)
);
You can built the table that contains the ids of the users with bad lists of email addresses
CREATE TABLE users_invalid_emails
SELECT id.email FROM users WHERE email LIKE 'email%' and email LIKE '%@domain.com';
ALTER TABLE users_invalid_emails ADD PRIMARY KEY (id);
Look over the content of users_invalid_emails. If the emails in that table are to be deleted, you can now do a DELETE JOIN:
DELETE A.* FROM users A INNER JOIN users_invalid_emails B USING (id);
Before you do this, make sure you have a backup of the table.
In your case, the code will be
CREATE TABLE myBBusers_invalid_emails
SELECT id.email FROM my_BBusers WHERE email LIKE 'email%' and email LIKE '%@domain.com';
ALTER TABLE myBBusers_invalid_emails ADD PRIMARY KEY (id);
DELETE A.* FROM my_BBusers A INNER JOIN myBBusers_invalid_emails B USING (id);
DROP TABLE myBBusers_invalid_emails;
Give it a Try !!!Free tutorials and interview questions from industry experts — learn the skill, then get ready to prove it.
Step-by-step SQL Server guides from industry experts
Common SQL Server interview questions, answered
Guides, tips and career advice on SQL Server from JanBask experts.
SQL Server Top 75 SSAS Interview Questions and Answers For Beginners & Experts
Prepare for your SSAS interview with our comprehensive guide featuring 75 top SQL Server Analysis Services interview questions…
SQL Server How to Become a SQL Database Administrator?
How to become a sql database administrator In 2025, discover what these professionals do, explore how much they earn and learn…
SQL Server OLAP vs OLTP: Key Differences, Architectures, Performance & Real-World Examples
Compare OLTP vs OLAP with clear definitions, architecture diagrams, real-world examples, and FAQs. Learn when to use each system…
SQL Server 70+ Most Asked SSIS Interview Questions for Freshers & Experienced
Prepare for your next SQL Server Integration Services (SSIS) interview with our top 70+ SSIS interview questions and answers.…