Let\'s say I have the following table:
CREATE TABLE orders (
Order_ID int,
Product_ID int,
PRIMARY KEY(Order_ID,Product_ID)
);
INSERT INTO orders VA
If I've understood you correctly:
Select ID
From table_name
where P_ID = 2
One way is to select all the lines that correspond to your subset.
Then group by order, and count how many correspondance you have. If it's equal to the size of your subset, then the order is eligible.
SELECT orders.order_id
FROM orders
WHERE orders.product_id in (2, 3)
GROUP BY orders.order_id
HAVING COUNT(1) = 2
Note that this works because you have define PRIMARY KEY(Order_ID,Product_ID)
, which is a very good idea!
Fiddle