Skip to content
Advertisement

How to find if a list/set is exactly within another list

My question is basically an extension of this question – How to find if a list/set is contained within another list

I have the same data, but with more exact same products –

I want to find the order(s) where the order has EXACTLY given product ids.

For example: If I search for 222 & 555, I should get order_id 1 as output since it only have those 2 exact product ids. And should not get order id 2 as output since it has an additional 333 product id.

Advertisement

Answer

You can still use having, but test for each product — and for the absence of any other product:

Note that this uses the MySQL shorthand, where boolean expressions are treated as numbers with 1 for true and 0 for false. The standard syntax is:

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement