0% found this document useful (0 votes)
30 views

SQL Join Ex-2

The document contains 10 SQL queries that retrieve various data from database tables: employee details for a specific order, shipper name for an order, order IDs that ordered a specific product unit, order dates for customers from a city, customer names who ordered the most expensive product, category name for a product ordered in a quantity, product name with highest ordered quantity, customer names who ordered after a date, customer names who ordered less than a quantity, and total price of products in a specific order.

Uploaded by

ahdb
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views

SQL Join Ex-2

The document contains 10 SQL queries that retrieve various data from database tables: employee details for a specific order, shipper name for an order, order IDs that ordered a specific product unit, order dates for customers from a city, customer names who ordered the most expensive product, category name for a product ordered in a quantity, product name with highest ordered quantity, customer names who ordered after a date, customer names who ordered less than a quantity, and total price of products in a specific order.

Uploaded by

ahdb
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

1.

Display the Employee details corresponding to OrderID=10261

SELECT e.EmployeeID,e.LastName,e.FirstName,e.BirthDate,e.Photo,e.Notes
FROM Employees e, Orders o
WHERE e.EmployeeID = o.EmployeeID and OrderId=10261;

2. Display the ShipperName for OrderID=10318.

SELECT s.ShipperName
FROM Shippers s , Orders o
WHERE s.ShipperID = o.ShipperID and o.OrderID=10318;

3. Display the OrderIDs who ordered for an item which has 1 kg pkg. Unit.

SELECT o.OrderID
FROM Products p ,OrderDetails o
WHERE p.ProductID = o.ProductID and p.Unit like '%1 kg pkg%';

4. Display the Order date when the Customers from the city, ‘Buenos Aires’
placed an order.

select o.OrderDate
FROM Customers c, Orders o
WHERE c.CustomerID = o.CustomerID and c.City='Buenos Aires';

5. Display the Customer names who ordered the costliest product.

SELECT C.CustomerName
FROM Customers AS C
JOIN Orders AS O ON C.CustomerID = O.CustomerID
JOIN OrderDetails AS OD ON O.OrderID = OD.OrderID
JOIN Products AS P ON OD.ProductID = P.ProductID
WHERE P.Price = (
SELECT MAX(Price)
FROM Products
);

6. Display the Category name of the product which was ordered in


quantity=33.

SELECT C.CategoryName
FROM Categories AS C
JOIN Products AS P ON C.CategoryID = P.CategoryID
JOIN OrderDetails AS OD ON P.ProductID = OD.ProductID
WHERE OD.Quantity = 33;

7. Display the Product name which has the highest quantity of order.

SELECT P.ProductName
FROM Products AS P
JOIN OrderDetails AS OD ON P.ProductID = OD.ProductID
GROUP BY P.ProductName
ORDER BY SUM(OD.Quantity) DESC
LIMIT 1;

8. Display the Customer names who placed an order after ‘1997-02-07’.

SELECT DISTINCT C.CustomerName


FROM Customers AS C
JOIN Orders AS O ON C.CustomerID = O.CustomerID
WHERE O.OrderDate > '1997-02-07';

9. Display the Customer names who ordered less than quantity=2 in their
orders.

SELECT DISTINCT C.CustomerName


FROM Customers AS C
JOIN Orders AS O ON C.CustomerID = O.CustomerID
JOIN OrderDetails AS OD ON O.OrderID = OD.OrderID
WHERE OD.Quantity < 2;

10. Display the sum of the price of products that was ordered in the
OrderID=10263.

SELECT SUM(P.Price) AS TotalPrice


FROM Products AS P
JOIN OrderDetails AS OD ON P.ProductID = OD.ProductID
WHERE OD.OrderID = 10263;

You might also like