tags:

views:

14

answers:

1

Hi all

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 that 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 ...

cheers

Paul

A: 

Warning: Test this query on test database first. I claim no responsibility for data lost by running this queery.

DELETE t FROM project AS p LEFT JOIN tasks AS t ON (p.id = t.project_id) WHERE p.id IS NULL

Mchl