This query returns exactly the office tuples I need to delete.
SELECT id, reference FROM office o
WHERE o.id NOT IN
(SELECT c.office_id FROM Contract c WHERE office_id IS NOT NULL)
AND o.reference IN
(SELECT o.reference FROM Contract c JOIN office o ON c.office_id = o.id WHERE office_id IS NOT NULL);
But when I write the query
DELETE FROM office
WHERE id NOT IN
(SELECT c.office_id FROM Contract c WHERE office_id IS NOT NULL)
AND reference IN
(SELECT o.reference FROM Contract c JOIN office o ON c.office_id = o.id WHERE office_id IS NOT NULL);
I have the following error : #1093 - You can't specify target table 'office' for update in FROM clause
But I really don’t see how to solve this..
Any help would be much appreciated!
try
since you can’t delete from a table where you are selecting from. But using
should do the trick