Basically, I just want to write a cleaner query than what I have, which involved setting up 2 temp tables. I'm reviewing orders placed in our company. Our OrderDetails table contains 2 key fields:
- the order id
- the product id that was ordered
So obviously, there will be one record in this table for each product purchased.
I want to create a query that returns the order id's of all orders that've purchased ProductId =1 AND ProductId = 2.
OrderDetailsId OrderId ProductId
1 123 1
2 456 1
3 456 3
4 789 1
5 789 2
6 789 3
In the above scenario, only orderId 789 should be returned because it's the only order that contains both productId's 1 & 2.
Thanks for any help you can provide.