Site icon Hip-Hop Website Design and Development

SQL NOT EXISTS in combination with LIKE doesn’t work

I’m trying to return those posts with post_type = "attachment" , where their meta_value (url) doesn’t appear in any post_content .

For now I’m trying to give the meta_value manually, which in this case is a image name speed1

I’ve cheked and there are some posts with the image "speed1.jpg" in the post_content.

When I select those WITH the word in the content, it works, the problem arises when I try to select everything else but those with the word in the content, using the query:

SELECT 
    i.ID,
    i.post_content,
    i.post_type
FROM
    wp_posts i
WHERE
    i.post_type = 'attachment'
    AND NOT EXISTS (SELECT * FROM wp_posts p WHERE p.post_type <> 'attachment' AND p.post_content LIKE "%speed1%")

this always returns empty. Why?