Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9154211
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T12:23:36+00:00 2026-06-17T12:23:36+00:00

I have a really strange problem. I simply want to select all posts that

  • 0

I have a really strange problem.

I simply want to select all posts that feature in two given categories.

Heres my SQL:

SELECT  wp_posts.ID 
FROM wp_posts 
INNER JOIN wp_term_relationships ON wp_posts.ID = wp_term_relationships.object_id
WHERE  wp_term_relationships.term_taxonomy_id  = 83  
   AND   wp_term_relationships.term_taxonomy_id  = 84

This should return one result but it doesnt return anything.

If I comment out:

*wp_term_relationships.term_taxonomy_id  = 83* 

The post im looking for is returned.

If I comment out:

*wp_term_relationships.term_taxonomy_id  = 84*

Again, the post is returned.

Why then,when both of these conditions are included, nothing is returned?

Any help will be appreciated.Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T12:23:37+00:00Added an answer on June 17, 2026 at 12:23 pm

    If you want to return all posts that have both those term_taxonomy_id‘s associated with them you can use:

    SELECT  p.ID 
    FROM wp_posts p
    INNER JOIN wp_term_relationships r
      ON p.ID = r.object_id
    WHERE  r.term_taxonomy_id IN (83, 84)
    GROUP BY p.ID 
    HAVING count(distinct r.term_taxonomy_id) =2
    

    This will return all records that have both taxonomy terms.

    Your query will not work because the term_taxonomy_id cannot have two values at the same time. You can change your query to use OR instead of AND or you can use the version I provided.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm facing a really strange problem that has me smoked. I have a fairly
Have a really strange problem with UTF8 characters. I have the following: All my
We have a really strange problem in xpages regarding dates, the Notesdocument we have
I have a really strange problem with SQL Server 2008. We have an e-commerce
I have a really strange problem and I'm completely puzzled. I have a piece
I'm having a really strange problem. I have 2 virtual machines running ubuntu 11.4
I have a kind of strange thing that I really nead for my text
I've come across a really strange problem. I have written a simple Deck class
I am having some strange problem and its really frustating me. I have a
I have a really strange problem with the standard logging module used in django

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.