-2

See Attached image

I'm creating a website in which a registered user can see a post only once.i have used a DB table (viewed posts) in which i save user id of the logged in user and post id of the post he viewed . i want to show only those posts to user which he has not seen yet from the (post) table. please help me how i can do this . i have tried left joint etc but none of them works well

i also tried this one but it not works

select * from post, viewed_post 
where post.p_id !=viewed_post.p_id 
  AND viewed_post.u_id!='$logged_in_user_id';
Shadow
  • 33,525
  • 10
  • 51
  • 64

1 Answers1

1

Use NOT IN operator:

select * from post
WHERE post.p_id NOT IN (
    SELECT p_id
    FROM viewed_post
    WHERE user_id = '$logged_in_user_id'
)
Rajdeep Paul
  • 16,887
  • 3
  • 18
  • 37
krokodilko
  • 35,300
  • 7
  • 55
  • 79