Skip to content
Advertisement

TSQL: Given a set of IDs, obtain all headers such that the set is included in the header’s children

I am looking for a query that would return all Order ID’s that contain a set of productIDs, but might include more products.

Data structure:

So given a set of productIDs, I want a query to return all orders that contain all (possibly more) products from the set.

Advertisement

Answer

You can use aggregation:

This assumes that there are no duplicate products in an order. If that is possible, use count(distinct od.productid).

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