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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.