0
我有两个表 - forum_topics
和topics_posts
。我想从forum_topics
中选择topics_posts
表中没有帖子的行,但无法弄清楚如何操作。请问一个SQL语句像这样存在:MySQL选择行不在另一个表中的行
select from * `forum_topics` where have no rows in `topics_posts`
我有两个表 - forum_topics
和topics_posts
。我想从forum_topics
中选择topics_posts
表中没有帖子的行,但无法弄清楚如何操作。请问一个SQL语句像这样存在:MySQL选择行不在另一个表中的行
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;
非常感谢你的工作好(外连接) – 2010-03-17 10:02:11