Docsity

Understanding SQL Joins: Types, Syntax, and Examples, Slides of Fundamentals of E-Commerce

Partial preview of the text

Download Understanding SQL Joins: Types, Syntax, and Examples and more Slides Fundamentals of E-Commerce in PDF only on Docsity!

Back to SELECT: The Join

  • Sometimes we want fields from more then

one table. To do this we use a JOIN.

BTW

: JET = Join Engine Technology.

  • Two Types:
    • INNER: Rows have only fields in one that

match the other.

  • OUTER: May include some of each with

NULLS for missing values.

Joins

  • Must use DOT (.) notation i.e.

TABLE.FIELD

  • Best constructed with a tool (actually all

queries are best constructed with a tool).

  • Most powerful feature in SQL. We

normalize tables for efficiency, joins allowus to view data de-normalized like in aspreadsheet.

Inner Joins

  • In an inner join the rows returned only

include those in which there is a matchingrow or rows from BOTH tables.

  • For example if I have a table of Customers

and Invoices and if there are customers without invoices or invoices without customersthose rows will NOT be included in therows returned from an inner join.

Join Example From Shop.mdb^ Query: SELECT Customer.CustomerID, Customer.NameLast,Customer.NameFirst, Sale.SaleID, Sale.SaleDate,SaleDetail.Quantity, SaleDetail.UnitPrice, Product.ProductNameFROM Product INNER JOIN ((Customer INNER JOIN Sale ONCustomer.CustomerID = Sale.CustomerID) INNER JOIN SaleDetailON Sale.SaleID = SaleDetail.SaleID) ON Product.ProductID =SaleDetail.ProductIDWHERE (((Customer.Voided)=0) AND ((Sale.Voided)=0))ORDER BY Customer.NameLast, Customer.NameFirst;

vAllOrders

: All Orders

Join Example Results