Here is the script to create my tables:
CREATE TABLE clients (
client_i INT(11),
PRIMARY KEY (client_id)
);
CREATE TABLE projects (
project_id INT(
Another method of deleting using a sub select that is better than using IN
would be WHERE
EXISTS
DELETE FROM posts
WHERE EXISTS ( SELECT 1
FROM projects
WHERE projects.client_id = posts.client_id);
One reason to use this instead of the join is that a DELETE
with JOIN
forbids the use of LIMIT
. If you wish to delete in blocks so as not to produce full table locks, you can add LIMIT
use this DELETE WHERE EXISTS
method.