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.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Problem returning order detail info.

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 | 1233
222 | 5999
222 | 9999

Any 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, productID
from yourtable
where order in (select order from yourtable where productID = '9999')
Go to Top of Page

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
Go to Top of Page
   

- Advertisement -