-3

I have 2 tables, one for storing a post and the other for users that has liked the post.

I want to fetch the posts only where user has not liked it.

Example

Posts Table:

post_id, title

Like Table:

like_id, post_id, user_id

I only want the list of posts where user has not liked it.

What should be the SQL query?

1 Answers1

0

SELECT POSTS.post_id FROM POSTS WHERE POSTS.post_id NOT IN (SELECT LIKE.post_id FROM LIKE,POSTS WHERE POSTS.post_id=LIKE.post_id);

yuri_1
  • 1
  • 4
  • MySQL does not understand the SQL standard `EXCEPT` and `INTERSECT` you need to simulate/emulate [those](http://www.mysqltutorial.org/mysql-intersect/).. Also if it would work in MySQL this query is also wrong because it should have been `INTERSECT` instead off `EXCEPT` – Raymond Nijland Mar 07 '19 at 13:50