Skip to content

Instantly share code, notes, and snippets.

@onegrx
Created November 12, 2015 13:14
Show Gist options
  • Select an option

  • Save onegrx/2b596962b2be9fa57c86 to your computer and use it in GitHub Desktop.

Select an option

Save onegrx/2b596962b2be9fa57c86 to your computer and use it in GitHub Desktop.
use joindb
select buyer_name, qty
from Buyers
cross join sales
select buyer_name, prod_name, qty
from buyers
inner join sales on buyers.buyer_id = sales.buyer_id
inner join produce on sales.prod_id = produce.prod_id
use northwind
select productname, unitprice, address
from products
inner join Suppliers as S on products.SupplierID = s.SupplierID
inner join Categories as C on products.CategoryID = c.CategoryID
where unitprice between 20 and 30
and CategoryName = 'Meat/Poultry'
select productname, unitprice, CompanyName
from products
inner join Categories as C on products.CategoryID = C.CategoryID
inner join Suppliers as S on products.SupplierID = S.SupplierID
where CategoryName = 'Confections'
select Customers.CompanyName, Customers.Phone
from Customers
inner join Orders as O on Customers.CustomerID = O.CustomerID
inner join Shippers as S on O.ShipVia = S.ShipperID
where year(ShippedDate) = 1997 and S.CompanyName = 'United Package'
select C.CompanyName, C.Phone
from Customers as C
inner join Orders as O on C.CustomerID = O.CustomerID
inner join [Order Details] as OD on O.OrderID = OD.OrderID
inner join Products as P on OD.ProductID = P.ProductID
inner join Categories as CA on P.CategoryID = CA. CategoryID
where CategoryName = 'Confections'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment