Home > OS >  SQL NOT EXISTS in combination with LIKE doesn't work
SQL NOT EXISTS in combination with LIKE doesn't work

Time:01-25

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?

CodePudding user response:

Could you do something like this

SELECT 
    i.ID,
    i.post_content,
    i.post_type
FROM
    wp_posts i
WHERE
    i.post_type = 'attachment'
    i.post_content NOT LIKE "%speed1%"

CodePudding user response:

Could you bring us with some information records from the Database to determine what is the problem.

  •  Tags:  
  • Related