Site icon Hip-Hop Website Design and Development

Manually query posts by taxonomy with MySQL

I’m trying to query posts from the WP database with the category uncategorised, while also joining the post meta table, but I can’t get it to work.
I get an empty result.

This is my query

SELECT * FROM wptests_posts wp
INNER JOIN wptests_postmeta wm ON (wm.`post_id` = wp.`ID`)
INNER JOIN wptests_term_relationships wtr ON (wp.`ID` = wtr.`object_id`)
INNER JOIN wptests_term_taxonomy wtt ON (wtr.`term_taxonomy_id` = wtt.`term_taxonomy_id`)
INNER JOIN wptests_terms wt ON (wt.`term_id` = wtt.`term_id`) AND
((wtt.`taxonomy` = 'category' AND  wt.`slug` = 'uncategorized'))

It seems to be the postmeta inner join on line 2. If i remove it, I get the expected results, except I don’t then get the post meta.

Any help is appreciated