Advanced MySQL: Combining queries
-
Hi everyone,
I’m beating my head against a wall trying to figure out how I can use MySQL to combine a couple of queries… the problem is they’re queries using the same tables.I know how to write an SQL query that finds posts in a certain category. This clause:
INNER JOIN wp_term_relationships as a ON (wp_posts.ID = a.object_id) INNER JOIN wp_term_taxonomy ON (wp_term_relationships.term_taxonomy_id = wp_term_taxonomy.term_taxonomy_id) WHERE 1=1 AND wp_term_taxonomy.taxonomy = 'category' AND wp_term_taxonomy.term_id IN ('3', '3')will limit the query to category 3, for instance. Likewise, I know how to search for particular tags — it’s the same clause, with ‘post_tag’ instead of ‘category’ etc.
However, what I’m trying to do is find posts that are BOTH in a certain category and have a certain tag. In category 3 with tag 8, for instance. I just can’t figure out how to structure the MySQL query. Anyone know how to do this?
The topic ‘Advanced MySQL: Combining queries’ is closed to new replies.