如何使用连接删除mysql行 [英] how to delete mysql rows using joins

查看:27
本文介绍了如何使用连接删除mysql行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

c2.execute("delete from entity_map where canon_id in (select canon_id from
entity_map_session where canon_id in (select canon_id from 
entity_map_session group by canon_id having count(canon_id) < 10))")

我想加快上面的一组操作.尤其是最后一个我们删除行的地方.最好的方法是什么?

I want to speed up the above set of operations. Especially the last one where we delete rows. What is the best way to do that?

推荐答案

针对 entity_map_session2 表的子查询正在做计数聚合,并且没有 WHERE>HAVING 子句,这意味着它不能被优化太多.但是,您可以去掉其中一个不必要的嵌套子查询,例如使用:

The subquery against the entity_map_session2 table is doing a count aggregation, and has no WHERE or HAVING clauses, which means that it cannot be optimized much. However, you may do away with one of the unnecessary nested subqueries, e.g. use:

DELETE
FROM entity_map2
WHERE canon_id IN (SELECT canon_id FROM entity_map_session2
                   GROUP BY canon_id HAVING COUNT(canon_id) < 10);

这篇关于如何使用连接删除mysql行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆