Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MS Access SQL Subquery Question

Status
Not open for further replies.

beeboroach

Technical User
May 7, 2012
3
US
I need to use a subquery to create a list that shows the description and price for all products that were ever ordered. It should not show products that were never ordered.

This is what my relationships look like:
Here's what I started with:
SELECT PRODUCT.Product_Description, PRODUCT.Standard_Price
FROM PRODUCT;

How do I make a subquery to exclude those that don't have an order id or..?
 
NVM, I think I got it...

SELECT PRODUCT.Product_Description, PRODUCT.Standard_Price
FROM PRODUCT INNER JOIN Order_line ON PRODUCT.Product_ID = Order_line.Product_ID
WHERE PRODUCT.Product_ID IN
(
SELECT Order_line.Product_ID
FROM Order_line
Where Order_line.Product_ID=PRODUCT.Product_ID
)

Needed to refresh on a lot of subquery info.
 
Why a subquery ?
SELECT DISTINCT PRODUCT.Product_Description, PRODUCT.Standard_Price
FROM PRODUCT INNER JOIN Order_line ON PRODUCT.Product_ID = Order_line.Product_ID

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Sorry if I didn't clarify, I was just trying to see how to use subqueries in that instant. I know how to use joins, thanks for your input though!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top