What would it be for WordPress 2.2?
It has different table names and probably structure. Can't figure it out. Found this on another thread about changes for 2.3:
$wpdb->categories is replaced by $wpdb->terms
$wpdb->post2cat is replaced by $wpdb->term_relationships
$wpdb->post2cat.post_id is replaced by $wpdb->term_relationships.object_id
$wpdb->post2cat.category_id is replaced by $wpdb->term_relationships.term_taxonomy_id
$wpdb->categories.cat_ID is replaced by $wpdb->terms.term_id
wp_terms now contains all the category (read: taxonomy) names and IDs.
wp_term_taxonomy contains the term (read category) ID, a description of what type it is (category, link_category, etc), the description and the number of posts/links in that taxonomy.
wp_term_relationships contains a lookup of an object_id (read: post ID, link ID, etc) and a term taxonomy ID (from the term_taxonomy table, which relates back to the category).
Other refs to look out for are (especially when they are used OUT of the above context):
cat_ID –> term_ID
categories –> terms
cat_name –> name
I get this far:
$query = "SELECT * FROM posts as wpost INNER JOIN post2cat ON (wpost.ID = post2cat.post_id) INNER JOIN term_taxonomy ON (post2cat.category_id = 3) AND term_taxonomy.taxonomy = 'category' AND term_taxonomy.term_id IN (3)";
I have no clue what to do with term_taxonomy and probably need a different structure anyway. Can't puzzle it together.