Select all records don't meet certain conditions in a joined table

后端 未结 2 1815
慢半拍i
慢半拍i 2020-12-22 01:41

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 t

相关标签:
2条回答
  • 2020-12-22 02:28
    SELECT  *
    FROM    posts
    WHERE   post_id NOT IN 
            (
            SELECT  comment_post
            FROM    comments
            WHERE   comment_date >= @deadline
            )
    
    0 讨论(0)
  • 2020-12-22 02:34
    SELECT *
    FROM posts p
    WHERE NOT EXISTS(
        SELECT 1
        FROM comments c
        WHERE c.comment_date >= 'deadline'
        AND p.post_id = c.post_id
    )
    
    0 讨论(0)
提交回复
热议问题