两个表相互关联,结果 只删除了第一个表 A(task)中数据,导致 B (task_apoly)表数据依旧在, 这个就不好了!由于数据量比较大,还不能直接删除B中所有数据,只能关联查询删除了
delete from task_apply where task_id IN select a.task_id from(select a.task_id from task_apply a LEFT JOIN task b on a.task_id = b.id where b.id is null)
写了一个这个关联 删除 本以为大工告成,结果sql不愿意
You can't specify target table 'dt_task_apply' for update in FROM clause
直接保存了,你说说你啊
然后查了资料才发现 不能这样写
需要把 下面查询数据 再重新查询一下给 delete
select a.task_id from task_apply a LEFT JOIN task b on a.task_id = b.id where b.id is null
结果是只能这样用了
delete from task_apply where task_id IN select a.task_id from(select a.task_id from task_apply a LEFT JOIN task b on a.task_id = b.id where b.id is null)