的是这两个MySQL之间的区别查询子查询和联接的子查询有什么区别?
select t.id,
(select count(c.id) from comment c where c.topic_id = t.id) as comments_count
from topic;
和
select t.id,comments.count from topic
left join
(
select count(c.id) count,c.topic_id from comment c group by topic_id
) as comments on t.id = comments.topic_id
我知道那里有没有太多的信息。只是想知道什么时候使用子查询并加入了子查询以及它们之间的区别。
感谢
你的第二个例子是一个派生表的连接。好处是派生表是一次生成,基于集合。第一个相关的子查询可能会在“topic”表的每一行中执行一次 – StuartLC
所以,你的意思是子查询可以检索单个记录吗?和第二个撤回清单? – reverbnation
@reverbnation如果你想提出一个StuartLC的问题,你应该用@ @ – 2015-06-14 15:38:16