Try a query

Sample queries

Start with a question about the data, then adapt the SQL for your own database engine.

AdventureWorks OLTP

Orders by customer

List sales orders with the account they belong to and their totals.

SELECT h."SalesOrderNumber", c."CustomerID", h."OrderDate", h."TotalDue" FROM "Sales.SalesOrderHeader" AS h JOIN "Sales.Customer" AS c USING ("CustomerID") ORDER BY h."OrderDate" DESC LIMIT 20;
Get the database →

AdventureWorks OLTP

Products on sales orders

Show products, ordered quantities, unit prices, and stored line totals.

SELECT p."Name", d."OrderQty", d."UnitPrice", d."LineTotal" FROM "Sales.SalesOrderDetail" AS d JOIN "Production.Product" AS p USING ("ProductID") ORDER BY d."SalesOrderID", d."SalesOrderDetailID" LIMIT 20;
Get the database →

AdventureWorks OLTP

Purchase orders by vendor

Summarize purchase orders with vendor names and recorded amounts.

SELECT v."Name", h."PurchaseOrderID", h."OrderDate", h."TotalDue" FROM "Purchasing.PurchaseOrderHeader" AS h JOIN "Purchasing.Vendor" AS v ON v."BusinessEntityID" = h."VendorID" ORDER BY h."OrderDate" DESC LIMIT 20;
Get the database →

AdventureWorks OLTP

Inventory by location

List current product inventory by production location.

SELECT p."Name", l."Name" AS "Location", i."Quantity" FROM "Production.ProductInventory" AS i JOIN "Production.Product" AS p USING ("ProductID") JOIN "Production.Location" AS l USING ("LocationID") ORDER BY p."Name", l."Name" LIMIT 20;
Get the database →