Let’s say I have a posts table that has many comments (and a comment belongs to a user).
How would I show all posts where a particular user hasn’t commented on?
Pretend I have a user in my database with an ID of 124;
select * from posts p left join comments c on p.id = c.post_id
where c.id is null or c.user_id <> 124
But that doesn’t seem right .. as what if the post has no comments?
You should be checking the
user_idfrom tablepostand not on tablecommentsbecause there are someuser_idthat doesn’t have any records yet on tablecomments.