SELECT returning data not seen by a particular user

Asked

Viewed 64 times

5

I’m having a hard time putting together Query

I have 2 tables:

  • video_visualizacoes with the fields visualizacao_id, video_id, conta_id (This field refers to the user who viewed the video)".
  • videos with the fields video_id, video_titulo e conta_id (This field refers to uploader of the video)"

I need a Query that returns all videos that have not yet been viewed by particular user.

  • 2

    You can post what you’ve tried so far?

  • 3

    It would be interesting to put an example of the tables, use this tool: http://lorefnon.me/plain-text-table/

2 answers

3

This way you’ll get

select v.* from videos v
where v.video_id not in (select t.video_id video_visualizacoes t where t.conta_id=v.conta_id)
and v.conta_id= id
  • 2

    Two Where in the same query? wouldn’t be one and there at the end.

  • Sorry, I will edit the post, actually it would be an and

  • 1

    Leandroluk noticed the gaffe and edited

0

Have you ever tried anything like:

SELECT videos.video_id
FROM videos 
JOIN video_visualizacoes ON videos.conta_id <> video_visualizacoes.conta_id 
ORDER BY videos.video_id DESC

Browser other questions tagged

You are not signed in. Login or sign up in order to post.