此查询准确返回我需要删除的办公室元组。
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);
但是当我写查询
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);
我有以下错误:#1093 - You can't specify target table 'office' for update in FROM clause
但我真的不知道如何解决这个问题..
任何帮助将非常感激!