0% found this document useful (0 votes)
8 views1 page

SQL Practice Part 5

The document contains SQL queries demonstrating various types of joins, including INNER JOIN and LEFT JOIN, to retrieve data from multiple tables such as Customers, Orders, OrderDetails, and Products. It includes examples of selecting customer names, order details, and calculating total spending per customer. Additionally, it showcases how to aggregate and order results based on specific criteria.

Uploaded by

pankajsspati8
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views1 page

SQL Practice Part 5

The document contains SQL queries demonstrating various types of joins, including INNER JOIN and LEFT JOIN, to retrieve data from multiple tables such as Customers, Orders, OrderDetails, and Products. It includes examples of selecting customer names, order details, and calculating total spending per customer. Additionally, it showcases how to aggregate and order results based on specific criteria.

Uploaded by

pankajsspati8
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

SQL Practice - 5.

Joins

Queries:
SELECT c.CustomerName, o.OrderID, o.OrderDate FROM Customers c JOIN Orders o ON
c.CustomerID = o.CustomerID;
SELECT c.CustomerName FROM Customers c LEFT JOIN Orders o ON c.CustomerID =
o.CustomerID WHERE o.OrderID IS NULL;
SELECT o.OrderID, p.ProductName, od.Quantity FROM Orders o JOIN OrderDetails od ON
o.OrderID = od.OrderID JOIN Products p ON od.ProductID = p.ProductID;
SELECT c.CustomerName, SUM(p.Price * od.Quantity) AS TotalSpent FROM Customers c JOIN
Orders o ON c.CustomerID = o.CustomerID JOIN OrderDetails od ON o.OrderID = od.OrderID
JOIN Products p ON od.ProductID = p.ProductID GROUP BY c.CustomerName ORDER BY
TotalSpent DESC;
SELECT p.ProductName, SUM(od.Quantity) AS TotalOrdered FROM OrderDetails od JOIN
Products p ON od.ProductID = p.ProductID GROUP BY p.ProductName ORDER BY TotalOrdered
DESC LIMIT 5;

You might also like