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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T17:59:54+00:00 2026-05-23T17:59:54+00:00

I have two tables, entities and components, each with a name and unique ID.

  • 0

I have two tables, entities and components, each with a name and unique ID. There is a third table mapping the many-to-many relationship between these two IDs called construction, containing the two columns, entity_ID and component_ID. An entity is composed of some number of components. So if the construction table looks like this:

+----------+---------------+
|entity_id |  component_id |
+----------+---------------+
|        1 |             1 | 
|        1 |             2 | 
|        2 |             2 | 
|        2 |             6 | 
+----------+---------------+

Entity 1 is made out of components 1,2, while entity 2 is made out of 2 and 6. The application I’m working on also has an available table containing the IDs of all available components. My question is this, how do I query the database to return the entities constructed strictly of components in the available table? In the given example, if 1,2 and 6 are all in the available table, then entities 1 and 2 should be returned. Otherwise, if 2 isn’t in the available table (but 1 and 6 are) then nothing is returned. I’m new to MySQL so if you could explain the logic as well that would be great.

  • 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-23T17:59:54+00:00Added an answer on May 23, 2026 at 5:59 pm

    I tested @Abdullah’s subquery and indeed got the opposite of what I wanted. After a little testing I ended up with the nested queries that give me what I was looking for:

    select distinct entity_id from construction 
    where entity_id not in (
        select entity_id from construction c left outer join available a on a.id = c.component_id 
        where a.id is null 
    );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have two Tables: Document: id, title, document_type_id, showon_id DocumentType: id, name Relationship: DocumentType
I have two tables: Table 1: ID, PersonCode, Name, Table 2: ID, Table1ID, Location,
Let's say, I have two tables, entities and tags. Relation between them is expressed
I have these two entities. One for Employees: [Table(Name = Employees)] public class Employee
I have two tables Group and Customer and of course two entities Group and
I have two tables that are joined together. A has many B Normally you
I am struggling linq to entities left outer join. I have two entities (tables):
I have two tables joined together with entities like this (entities anonymized, and trimmed
Suppose there are two entities EntityA and EntityB. Two tables are defined for both
I have two tables, Book and Tag , and books are tagged using the

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.