There is a mySQL table which stores links to videos added to the post.

id | post_id | host | link 1 | 15 | youtube | youtube.com 2 | 15 | vimeo | vimeo.com 3 | 20 | youtube | youtube.com 4 | 20 | youtube | youtube.com 6 | 34 | vimeo | vimeo.com 6 | 35 | vimeo | vimeo.com 6 | 36 | youtube | youtube.com 

Tell me how to make a request to choose from the ID database of posts that do not have a link to youtube? In this example, post_id 34 and 35 should be selected.

Now I select all the records and do not filter them out for PHP, but this is in my opinion not very true, because I think that you can immediately choose the right ones.

  • Add to your request something like this: WHERE link! = 'youtube.com' - Edward
  • It would be very simple. link I cut it so it didn’t let me publish, full links to videos are stored there - jemxx
  • Well then you can add the following condition to the query: WHERE link NOT LIKE '%youtube.com%' - Edward

2 answers 2

 SELECT id FROM <table> WHERE post_id NOT IN ( SELECT post_id FROM <table> WHERE host = 'youtube' ) 

- instead of <table> name of your table.

     select post_id from Table group by post_id having sum(link='youtube.com')=0