I need to fetch the list of posts of a certain post type with the names of the categories they are associated to. Here is the direct mysql query:
select ID, post_title, wp_terms.name FROM wp_posts
join wp_term_relationships on wp_term_relationships.object_id = wp_posts.ID
join wp_term_taxonomy on wp_term_taxonomy.term_taxonomy_id = wp_term_relationships.term_taxonomy_id
join wp_terms on wp_terms.term_id = wp_term_taxonomy.term_id
where wp_posts.post_type = 'post_type_slug'