I'm new to MySQL and I'm having problem with a query using PHP. See the three last lines.
$query = "
SELECT post_content, slug, ID
FROM wp_posts
INNER JOIN wp_term_relationships
ON wp_posts.ID = wp_term_relationships.object_id
INNER JOIN wp_terms
ON wp_term_relationships.term_taxonomy_id = wp_terms.term_id
INNER JOIN wp_postmeta
ON wp_posts.ID = wp_postmeta.post_id
WHERE post_status = 'publish' AND slug = 'a-slug' AND meta_key <> 'include' AND meta_key <> 'exkludera'
OR post_status = 'publish' AND slug = 'a-slug' AND meta_key = 'include' AND meta_value = '72'
OR post_status = 'publish' AND slug = 'a-slug' AND meta_key = 'exclude' AND meta_value <> '72'
";
With the three last lines I want to say:
Row 1) Select query if it: Is publish, Has a-slug and doesnt have meta_key "include" or "exclude"
Row 2) Select query if it: Is publish, Has a-slug, have meta_key "include" and meta_value is '72'
Row 3) Select query if it: Is publish, Has a-slug, have meta_key "exclude" and meta_value is not '72'
But it gives me back double or tripple of each select. It should only be selected if it matchhes one of these three senarios. What am I doing wrong?