SELECT DISTINCT wposts.*
FROM wp_2_posts wposts, wp_2_postmeta wpostmeta, wp_2_postmeta wpostmeta1, wp_2_term_taxonomy, wp_2_terms, wp_2_term_relationships
WHERE wposts.ID = wpostmeta.post_id
AND wp_2_terms.term_id = '8'
AND wp_2_term_taxonomy.term_id = wp_2_terms.term_id
AND wp_2_term_taxonomy.term_taxonomy_id = wp_2_term_relationships.term_taxonomy_id
AND wp_2_term_relationships.object_id = wposts.ID
AND wpostmeta.meta_key = 'validity'
AND wpostmeta.meta_value > '".$logic_date."'
AND wpostmeta1.meta_key != 'permanent'
AND wposts.post_status = 'publish'
AND wposts.post_type = 'post'
ORDER BY wposts.post_date DESC
Good advice so far, heres the 'evolved' query which still does not use the second meta_key != 'permanent_listing'
SELECT wposts.* FROM wp_2_posts wposts LEFT JOIN wp_2_postmeta wpostmeta ON wposts.ID = wpostmeta.post_id LEFT JOIN wp_2_term_relationships wrelationships ON wrelationships.object_id = wposts.ID LEFT JOIN wp_2_term_taxonomy wtaxonomy ON wtaxonomy.term_taxonomy_id = wrelationships.term_taxonomy_id LEFT JOIN wp_2_terms wterms ON wtaxonomy.term_id = wterms.term_id WHERE wterms.term_id = '--category id here--' AND wpostmeta.meta_key = 'wpx_validity' AND wpostmeta.meta_value > '--todays date here--' AND wpostmeta.meta_key != 'permanent_listing' AND wposts.post_status = 'publish' AND wposts.post_type = 'post' ORDER BY wposts.post_date DESC
LEFT JOIN and INNER JOIN seem to do the same thing. the following indexes exist: wp_2_terms.term_id, wp_term_taxonomy.term_taxonomy_id, wp_2_term_relationships.object_id wp_2_postmeta has a meta_id index, and fields: post_id, meta_key, meta_value.
this query is running on WPMU.