[英]MySQL Select where rows are not in another table
我有两个表forum_topics
和topics_posts
。 我想从forum_topics
中选择在topics_posts
表中没有帖子的topics_posts
,但是无法弄清楚该怎么做。 是否存在这样的SQL语句:
select from * `forum_topics` where have no rows in `topics_posts`
我想您想要这样的东西:
select * from forum_topics t
where not exists (
select * from topics_posts p
where p.topic_id = t.id
);
尽管使用外部联接,但可能比子查询快一点:
select * from forum_topics t left outer join forum_posts p
on t.id = p.topic_id
where p.id is null;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.