Delete from tasks where project.find(project_id) is null
The title of this question is a very rough version of the query that I'd like to execute.
I've deleted project tasks without a user id, and I now want to delete tasks related to the projects th开发者_运维技巧at I've just deleted. Of course I probably should have just done it all with one query ... will take any suggestions for that query also, because I will be using it in future.
But for now, I need to delete project tasks which have a non-existent project associated ... i.e. a project_id that has no project associated ...
Warning: Test this query on a test database first. I claim no responsibility for data lost by running this query against production data.
DELETE t FROM project AS p LEFT JOIN tasks AS t ON (p.id = t.project_id) WHERE p.id IS NULL
精彩评论