Table1 is basically the routing table that contains all the components for the different parts, and table2 is a certain set of components that I care about. What I need to find is all the parts in table1 where every component for that part is in table2. For example:
The result I want to return from table 2 would simply be (002). Since (001) has component (B) in its bill of materials, I don't want to select it. The way I've done this so far is by finding the parts that have components that are NOT in table2, and then finding the parts that are NOT in that list:
INSERT INTO table3 SELECT part FROM table1 WHERE component NOT IN (SELECT part FROM table2);
SELECT part FROM table1 WHERE part NOT IN (SELECT part FROM table3);
The problem with this is that the first query runs extremely slow. Is there a faster way to process the data, and possibly avoid creating table3?
Thanks in advance for any help!