MySQL Forums
Forum List  »  Newbie

Multiple Metavalue Query
Posted by: Larry Woods
Date: August 05, 2019 04:49PM

I am executing the following query:

SELECT wp_posts.* FROM wp_posts INNER JOIN wp_postmeta ON wp_posts.ID = wp_postmeta.post_id
WHERE 1 = 1
AND ( wp_postmeta.`meta_key` = 'post_end' AND wp_postmeta.`meta_value` = '08-05-2019' )
AND ( wp_postmeta.`meta_key` = 'post_start' AND wp_postmeta.`meta_value` = '08-05-2019' )
AND wp_posts.post_name = 'test-page'
AND wp_posts.post_type = 'post'
GROUP BY wp_posts.ID
ORDER BY wp_posts.post_date DESC

There is a meta_value of '08-05-2019' for each of the meta_keys. When I execute this query I get NO results but if I remove either of the meta_key tests the query will return the record. It doesn't matter which meta_key I remove; one meta_key test works and two do not. I have bracketed the tests with parens so that the tests are made separately.

Options: ReplyQuote


Subject
Written By
Posted
Multiple Metavalue Query
August 05, 2019 04:49PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.