Welcome Back

Google icon Sign in with Google
OR
I agree to abide by Pharmadaily Terms of Service and its Privacy Policy

Create Account

Google icon Sign up with Google
OR
By signing up, you agree to our Terms of Service and Privacy Policy
Instagram
youtube
Facebook

Retrieve Orders, Products, and Quantities Using OrderDetails in SQL

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: