CREATE TABLE orders (
Order_ID int,
Product_ID int,
PRIMARY KEY(Order_ID,Product_ID)
);
INSERT INTO orders VALUES (1,1), (1,2), (1,3), (2,2), (2,3), (3,3), (3,4);
Each order has a set of products; how do I get all orders which have the product set of the order 2 as a subset of their product sets?
I want to get as results
OrderID
--
1
2
For further understanding:
In the example: The order 2 has products {2,3}
The result must be orders 1 and 2, because the order 1 has products {1,2,3} — it has subset {2,3}. On the other hand, the order 3's product set is {3,4} — it doesn't have subset {2,3}, so it must not returned in the result.