Hi,
Sorry if this is not the right place to post mysql questions. I just know that there are a lot of great people that are experts that are willing to help out.
I'm sure there is a way to write sql query to get this, I just could not figure it out. Please help me. Thanks a lot.
I have a table order: in the table there is order_id & product_id, the purpose of table is to keep track of each order and the products in that order.
For example: order_id=1, has products: 3,4,5. Which correspond to table entry:
order_id, product_id:1,3 1,4 1,5
My question is how do I write a sql query that can get a list of order_id that contains products 3,4,5 only. Given 3,4,5 I want it return order_id 1 only because it's the only product contains products 3,4,5. If given 3,4 as products, I want query to return both order1 and order2 because they both contains product 3,4.
Thanks a lot.
here is some sample data:
order_id | product_id
1 | 3
1 | 4
1 | 5
2 | 4
2 | 3
3 | 4
3 | 2
as you can see, order1 has product 3,4,5; order2 has product 4,3; and order3 has product 4,2.