0

I am in the process of learning SQL. I have a table that has the details of all orders placed. I need to locate all order that contain a specific item. SO i need to select the ItemID = 102011 to get the order numbers and them select all of the records by OrderId that have that item. I am not sure exactly how to make this happen.

Everything is in one table.

Thanks

1
  • Please add the table definitions. This would help with answering your question.
    – Pieter
    Oct 28, 2011 at 14:03

3 Answers 3

0

Try something like this (assuming a certain amount of your table structure):

select *
from yourOrdersTable
where ItemID = 102011
order by OrderId
0

Not sure what you mean by everything is in one table. Can you post the table structures? In an offshot that this is what you are looking for:

SELECT * FROM <orders_table> 
WHERE order_id IN (SELECT * FROM <orders_table> WHERE ItemID = 102011)

or this

SELECT * FROM <orders_table> WHERE ItemID = 102011 ORDER BY OrderId
0

This will likely depend on your flavour of SQL, but in SQL Server something like the following will work fine:

SELECT * FROM OrdersItems WHERE OrderID IN (SELECT OrderID FROM OrderItems WHERE ItemId = 102011)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.