mysql in 子查询 效率慢,对比

Posted 鴻飛

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了mysql in 子查询 效率慢,对比相关的知识,希望对你有一定的参考价值。

 desc SELECT id,detail,groupId from hs_knowledge_point where groupId in (
    SELECT groupId from hs_knowledge_point where groupId>0 GROUP BY groupId HAVING COUNT(groupId) > 1 
    UNION all
    SELECT groupId from hs_knowledge_point_commit where groupId>0 GROUP BY groupId HAVING COUNT(groupId) > 1 
)
UNION ALL
SELECT id,detail,groupId from hs_knowledge_point_commit where groupId in (
    SELECT groupId from hs_knowledge_point where groupId>0 GROUP BY groupId HAVING COUNT(groupId) > 1 
    UNION all
    SELECT groupId from hs_knowledge_point_commit where groupId>0 GROUP BY groupId HAVING COUNT(groupId) > 1 
)
View Code
SELECT id,detail,groupId from hs_knowledge_point where groupId in (
    select groupId from (
        SELECT groupId from hs_knowledge_point where groupId>0 GROUP BY groupId HAVING COUNT(groupId) > 1 
        UNION all
        SELECT groupId from hs_knowledge_point_commit where groupId>0 GROUP BY groupId HAVING COUNT(groupId) > 1 
    ) tmp
)
UNION ALL
SELECT id,detail,groupId from hs_knowledge_point_commit where groupId in (
    select groupId from (
        SELECT groupId from hs_knowledge_point where groupId>0 GROUP BY groupId HAVING COUNT(groupId) > 1 
        UNION all
        SELECT groupId from hs_knowledge_point_commit where groupId>0 GROUP BY groupId HAVING COUNT(groupId) > 1 
    ) tmp
)
View Code

 

 

 

 

以上是关于mysql in 子查询 效率慢,对比的主要内容,如果未能解决你的问题,请参考以下文章

mysql 子查询 优化

MySQL - SELECT WHERE field IN(子查询) - 为啥非常慢?

MySQL:在 WHERE 子句中带有 NOT IN 的从属子查询非常慢

MySql中in和exists效率

mysql in子查询的优化

那个mysql 子查询和连接查询 一般常用哪个 谁效率高些