So you have a table where you want to delete a bunch of rows, based on a particular column being matched in another table.

This is easily achievable with MySQL.

1
2
3
4
DELETE FROM TABLE1
WHERE domain IN (
	SELECT domain FROM TABLE2
)

The above SQL will delete all rows in TABLE1 that are found in TABLE2.

But what if we need to limit which records are returned from TABLE2?

That’s simple too. All we need to do is add a traditional WHERE clause to our select statement.

1
2
3
4
5
DELETE FROM TABLE1
WHERE domain IN (
	SELECT domain FROM TABLE2
	WHERE column1='1' AND column2<>'2'
)