SQL Join Ex-2
SQL Join Ex-2
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;
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';
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
);
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;
9. Display the Customer names who ordered less than quantity=2 in their
orders.
10. Display the sum of the price of products that was ordered in the
OrderID=10263.