This document lists 15 SQL commands that perform various operations like selecting data from tables, filtering on conditions, aggregating data using functions, joining tables, ordering results, and more. The commands select data from tables like Orders, Order Details, Products, Employees, and perform tasks like counts, sums, filters and more.
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
0 ratings0% found this document useful (0 votes)
39 views1 page
Module 11 - Writing SQL Queries (In Access)
This document lists 15 SQL commands that perform various operations like selecting data from tables, filtering on conditions, aggregating data using functions, joining tables, ordering results, and more. The commands select data from tables like Orders, Order Details, Products, Employees, and perform tasks like counts, sums, filters and more.
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1/ 1
15 SQL commands
1. SELECT ProductName FROM [Order Details] AS OD, Products AS P
WHERE OD.ProductID = P.ProductID AND OD.OrderID = 10249 2. SELECT * FROM Orders WHERE OrderDate = (SELECT MAX(OrderDate) FROM Orders) 3. SELECT OrderID, SUM(UnitPrice * Quantity * (1 Discount)) AS OrderTotal FROM [Order Details] GROUP BY OrderID 4. SELECT OrderID, SUM(UnitPrice * Quantity * (1 Discount)) AS OrderTotal FROM [Order Details] GROUP BY OrderID HAVING SUM(UnitPrice * Quantity * (1 Discount)) > 1000 5. SELECT OrderID, Count(*) AS OrderLineCount FROM [Order Details] GROUP BY OrderID 6. SELECT OrderID, Count(*) AS OrderLineCount FROM [Order Details] GROUP BY OrderID HAVING Count(*) >= 3 7. SELECT OrderID, Count(*) AS OrderLineCount FROM [Order Details] WHERE OrderID IN (SELECT OrderID FROM [Order Details] WHERE ProductID IN (2,3)) GROUP BY OrderID 8. SELECT OrderID, Count(*) AS OrderLineCount FROM [Order Details] WHERE OrderID IN (SELECT OrderID FROM [Order Details] WHERE ProductID IN (2,3)) GROUP BY OrderID HAVING Count(*) >= 3 9. SELECT OrderID, ProductName FROM [Order Details], Products WHERE [Order Details].ProductID = Products.ProductID ORDER BY OrderID 10. SELECT OrderID, CustomerID, OrderDate, FirstName, LastName FROM Orders AS O, Employees AS E WHERE O.EmployeeID = E.EmployeeID AND OrderDate BETWEEN #9/1/1994# AND #9/30/1994# ORDER BY OrderID 11. SELECT DISTINCTROW [Product Sales for 1995].CategoryName, Sum([Product Sales for 1995].ProductSales) AS CategorySales FROM [Product Sales for 1995] GROUP BY [Product Sales for 1995].CategoryName 12. SELECT [Product List].ProductID, [Product List].ProductName FROM Products AS [Product List] WHERE ((([Product List].Discontinued)=No)) ORDER BY [Product List].ProductName; 13. SELECT * FROM NewCustomerTable 14. SELECT * FROM Suppliers where country='uk' and city<>'london' 15. SELECT COUNT(*) AS MyCondiments FROM Products WHERE CategoryID =2