Imagine that you have two tables.
Table bar:
+-------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+--------------+------+-----+---------+-------+
| name | varchar(255) | YES | | NULL | |
+-------+--------------+------+-----+---------+-------+
Table foo:
+------------------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------------+--------------+------+-----+---------+-------+
| name_alternative | varchar(255) | YES | | NULL | |
+------------------+--------------+------+-----+---------+-------+
And you want to remove the rows from table bar that have the same name value as the field name_alternative from table foo
I could use the following query:
DELETE FROM foo WHERE name IN (SELECT name_alternative FROM bar);
But this takes a very long time to execute having a large amount of records in both tables.
So I was wondering if there is a better alternative to this query.