Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
Goalie35
Yak Posting Veteran
81 Posts |
Posted - 2010-07-12 : 17:10:56
|
I have to create an "Orders" query but I'm having trouble doing so...If a particular product was ordered as part of a customer's order, I need to return ALL products associated with that order.For example, if a customer placed an order (Order #222) for 3 products, one of the products being the particular product we're trying to single out(we'll call it productID "9999", then we need to return the following:Order#| ProductID#---------------------222 | 1233222 | 5999222 | 9999Any idea how I can return all products associated with an order that contains this particular product in question?Thanks. |
|
singularity
Posting Yak Master
153 Posts |
Posted - 2010-07-12 : 19:30:45
|
select order, productIDfrom yourtablewhere order in (select order from yourtable where productID = '9999') |
 |
|
Sachin.Nand
2937 Posts |
Posted - 2010-07-13 : 03:22:32
|
Ideally shouldn't you be storing ProductId in Orders tables?Limitations live only in our minds. But if we use our imaginations, our possibilities become limitless. PBUH |
 |
|
|
|
|