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

  • Home
  • SEARCH
  • 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 86561
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T22:15:55+00:00 2026-05-10T22:15:55+00:00

I have three tables in the many-to-many format. I.e, table A, B, and AB

  • 0

I have three tables in the many-to-many format. I.e, table A, B, and AB set up as you’d expect.

Given some set of A ids, I need to select only the rows in AB that match all of the ids.

Something like the following won’t work:

‘SELECT * FROM AB WHERE A_id = 1 AND A_id = 2 AND A_id = 3 AND … ‘ As no single row will have more than one A_id

Using, an OR in the sql statment is no better as it yields results all results that have at least one of the A ids (whereas I only want those rows that have all of the ids).

Edit:

Sorry, I should explain. I don’t know if the actual many-to-many relationship is relevant to the actual problem. The tables are outlined as follows:

Table People int id char name  Table Options int id char option  Table peoples_options int id int people_id int option_id 

And so I have a list of people, and a list of options, and a table of options and people.

So, given a list of option ids such as (1, 34, 44, …), I need to select only those people that have all the options.

  • 1 1 Answer
  • 1 View
  • 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. 2026-05-10T22:15:56+00:00Added an answer on May 10, 2026 at 10:15 pm

    A bit of a hacky solution is to use IN with a group by and having filter. Like so:

    SELECT B_id FROM AB WHERE A_id IN (1,2,3) GROUP BY B_id HAVING COUNT(DISTINCT A_id) = 3; 

    That way, you only get the B_id values that have exactly 3 A_id values, and they have to be from your list. I used DISTINCT in the COUNT just in case (A_id, B_id) isn’t unique. If you need other columns, you could then join to this query as a sub-select in the FROM clause of another select statement.

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

Sidebar

Related Questions

No related questions found

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.