I have a database which stores the products available on the market and products, "still under development", in two separate tables ( market_productand dev_product). The third table (substance) contains all the substances from which the product can be made. The other two tables ( marked_product_compand dev_product_comp) Mantegna.
I want to choose products still under development that are made from the same ingredients as the products they sell.
In the following (simplified) example, the query should select a product with ID = 2 from the dev_product table.
CREATE table market_product (ID SERIAL PRIMARY KEY);
CREATE table dev_product (ID SERIAL PRIMARY KEY);
CREATE table substance (ID SERIAL PRIMARY KEY);
CREATE table market_product_comp (prodID SERIAL, substID SERIAL, PRIMARY KEY(prodID,substID));
CREATE table dev_product_comp (devID SERIAL, substID SERIAL, PRIMARY KEY(devID,substID));
INSERT INTO market_product VALUES (1),(2);
INSERT INTO dev_product VALUES (1),(2);
INSERT INTO substance VALUES (1),(2),(3);
INSERT INTO market_product_comp VALUES (1,1),(1,2),(2,3);
INSERT INTO dev_product_comp VALUES (1,2),(2,1),(2,2);
How to write such a request?
UPDATE:
Sorry, I didn’t notice that I asked my question ambiguously.
, , . , dev_product, {1,2} market_product, {1,2,3}, dev_product, , , .