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

List Orders with Product Details in SQL

List Orders with Product Details in SQL

orders Table:

OrderDetails Table:

producs Table:

Query Explanation:

● SELECT Orders.OrderID, Products.ProductName, OrderDetails.Quantity, Products.Price
 Displays each order's ID, the name of the product in the order, quantity ordered, and the product's price.

● FROM OrderDetails
 Begins with the OrderDetails table, which connects orders to products.

● JOIN Orders ON OrderDetails.OrderID = Orders.OrderID
 Links each order detail to its corresponding order using the OrderID.

● JOIN Products ON OrderDetails.ProductID = Products.ProductID
 Links each order detail to the product details using the ProductID.

 

SQL Query:

USE SalesInventoryDB;

select orders.OrderID,
products.ProductName,
orderdetails.Quantity,
products.UnitPrice
from orderdetails
join orders on  orderdetails.OrderID= orders.OrderID
join products on orderdetails.ProductID = products.ProductID;

 

Output: