在联接表中选择所有不满足某些条件的记录 [英] Select all records don't meet certain conditions in a joined table

查看:34
本文介绍了在联接表中选择所有不满足某些条件的记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我们在这里有两个表,即帖子和评论,关系是一对多的,在评论表中有一个字段调用comment_date.

Let's say we have two tables here , posts and comments, the relations is one to many, there has a field call comment_date in the comments table.

现在,我很难获得预期的结果,如下所示:

Now I am struggle to get the expected results as follow:

所有帖子在特定日期后都没有评论,我可以通过SQL语句来完成此操作吗?

All the posts have no comments after a certain date, can I done this by a SQL statement?

推荐答案

SELECT *
FROM posts p
WHERE NOT EXISTS(
    SELECT 1
    FROM comments c
    WHERE c.comment_date >= 'deadline'
    AND p.post_id = c.post_id
)

这篇关于在联接表中选择所有不满足某些条件的记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆