Retrieve Orders, Products, and Quantities Using OrderDetails in SQL
×
Join our community on Telegram!
Join the biggest community of Pharma students and professionals.
Retrieve Orders, Products, and Quantities Using OrderDetails in SQL
OrderDetails Table:

orders Table:

products Table:

Query Explanation:
● SELECT Orders.OrderID, Products.ProductName, OrderDetails.Quantity
Displays the order ID, product name, and the quantity of each product in the order.
● FROM OrderDetails
Starts from the OrderDetails table which links orders and products.
● JOIN Orders ON OrderDetails.OrderID = Orders.OrderID
Joins the Orders table to get order information.
● JOIN Products ON OrderDetails.ProductID = Products.ProductID
Joins the Products table to get product names.
SQL Query:
USE SalesInventoryDB;
SELECT
Orders.OrderID,
Products.ProductName,
OrderDetails.Quantity
FROM OrderDetails
JOIN Orders ON OrderDetails.OrderID = Orders.OrderID
JOIN Products ON OrderDetails.ProductID = Products.ProductID;
Output:

