我正在使用MySql 5.5.37。我试图找出一种更快的方法来编写以下查询。我有两个表,access_code和教室。“教室”表具有对access_code表的主键的外键约束(access_code_id)。我正在尝试删除access_code表中的记录,这些记录没有指向教室表的链接,并且具有特定的类型ID。所以我在跑步…
delete from access_code where id in (select q.* from (select a.id FROM access_code a left join lyc_classroom c on a.id = c.access_code_id where a.access_code_type = 2 and c.access_code_id is null) q);
这需要很长时间。有没有更快的方法来执行上述查询?
您不需要子查询。使用delete ... join
语法
delete a
from access_code a
left join lyc_classroom c on a.id = c.access_code_id
where a.access_code_type = 2 and c.access_code_id is null
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句