繁体   English   中英

MySQL选择行不在另一个表中的位置

[英]MySQL Select where rows are not in another table

我有两个表forum_topicstopics_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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM