Jump to content

Query help


brianlange

Recommended Posts

I have a posts table, a category table and a join table. The relationship between posts and categories is many to many.

I want to query all posts that are not assigned to any of a certain group of categories.

 

The query below doesn't work because the result set is only matching records. I don't know whether a particular record does not match categories 21, 22, or 23. The only solution I have at the moment is too loop through every record and check for a matching record in the join table. This would work but it seems a little tedious to do.

 

SELECT *

FROM  `wp_term_relationships` tr

JOIN wp_posts p ON p.ID = tr.object_id

WHERE p.post_status =  "publish"

AND tr.object_id NOT

IN ( 21, 22, 23 )

 

Thanks,

 

-Briano

Link to comment
https://forums.phpfreaks.com/topic/238402-query-help/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.