=========
EXAMPLES:
———
SELECT Last(wp_terms.name) AS LastOfname, wp_posts.post_title, wp_posts.post_content, wp_term_taxonomy.taxonomy, wp_posts.post_type, wp_posts.post_status
FROM ((wp_posts LEFT JOIN wp_term_relationships ON wp_posts.ID = wp_term_relationships.object_id) LEFT JOIN wp_term_taxonomy ON wp_term_relationships.term_taxonomy_id = wp_term_taxonomy.term_taxonomy_id) LEFT JOIN wp_terms ON wp_term_taxonomy.term_id = wp_terms.term_id
GROUP BY wp_posts.post_title, wp_posts.post_content, wp_term_taxonomy.taxonomy, wp_posts.post_type, wp_posts.post_status
HAVING (((wp_term_taxonomy.taxonomy)=”category”) AND ((wp_posts.post_type)=”post”) AND ((wp_posts.post_status)=”publish”));

———
$querystr = “SELECT * FROM $wpdb->posts LEFT JOIN $wpdb->term_relationships ON($wpdb->posts.ID = $wpdb->term_relationships.object_id) LEFT JOIN $wpdb->term_taxonomy ON($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id) WHERE ($wpdb->term_taxonomy.term_id = 7 AND $wpdb->term_taxonomy.term_id <> 10 AND $wpdb->term_taxonomy.taxonomy = ‘category’ AND $wpdb->posts.post_type = ‘post’ AND $wpdb->posts.post_status = ‘publish’)”;

=========
REF:
———
http://wordpress.stackexchange.com/questions/2793/sql-query-to-select-posts-from-multiple-categories


http://www.anysitesupport.com/wordpress-query-posts-via-sql/