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 7079355
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:39:45+00:00 2026-05-28T06:39:45+00:00

I have this cross_reference table, post_id | cat_id —————– 3 11 —————– 3 2

  • 0

I have this cross_reference table,

post_id | cat_id
-----------------
3          11
-----------------
3          2
-----------------
4          5
-----------------
4          6
-----------------
4          2
-----------------
5          8
-----------------
5          13

The problem is that this query does not return anything….

SELECT DISTINCT post_id FROM posts_categories WHERE cat_id = 11 AND cat_id = 2

I expect it to return ‘3’…

What am I doing wrong?

  • 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-05-28T06:39:45+00:00Added an answer on May 28, 2026 at 6:39 am

    It is actually OR, not AND. Or better:

    SELECT DISTINCT post_id FROM posts_categories WHERE cat_id IN (11,2);
    

    Though I’d expect it to return 3 and 4.

    UPDATE: (based on the comment)

    SELECT post_id
    FROM post_categories WHERE cat_id IN (2,12)
    GROUP BY post_id HAVING count(*)=2;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a cross reference table that looks like this: id document_id subject_id 1
I have this code in jQuery, that I want to reimplement with the prototype
I have this idea for a free backup application. The largest problem I need
I have this RewriteRule that works too well :-) RewriteRule ^([^/]*)/$ /script.html?id=$1 [L] The
I Have Database that contains 4 tables TABLE TBLCARTITEM (CART_ID, ITEM_ID, PROMOTION_ID, many more
I have Plan table that has a one to many relationship with a Price
I have two simple tables in my database. A card table that contains Id,
I have the following table structures CREATE TABLE [dbo].[WorkItem]( [WorkItemId] [int] IDENTITY(1,1) NOT NULL,
I have a table with composite primary keys. This is a cross reference table
I have a SampleDB that contains 3 tables. Table Employees (EmployeeID, EmployeeName) Table Projects

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.