Docsity

Outer Joins: Understanding Left, Right and Full Joins, Slides of Fundamentals of E-Commerce

Partial preview of the text

Download Outer Joins: Understanding Left, Right and Full Joins and more Slides Fundamentals of E-Commerce in PDF only on Docsity!

Outer Joins

• In an outer join it is possible to get backrows from one or both table for which thereis no matching row in the other table.• For example if I have a table of Customersand Invoices and if there are customers without invoices or invoices with out customersI can still do a join that returns all of therows.

Outer Joins: Left or Right • Good for – detecting mismatches– detecting missing records– Reporting on records that might not have sub-records or detail information • LEFT implies all record from left table thatmay or not have records in right table.• RIGHT: is the opposite

Venn Diagrams of Joins

Inner: On the recordsthat match in both

Left: All the recordsIn A and the matchingOnes in B

Right: All the recordsin B and the matchingones in A

A^

B^

A^

A

B^

B Docsity.com

Outer Join: Example Find customers without Orders.Note use of NULL.

SELECT Customer.CustomerID, Customer.NameFirst,Customer.NameLastFROM Customer Left JOIN Sale ON Customer.CustomerID =Sale.CustomerIDWHERE (((Sale.SaleID) Is Null));^ CustomerID

NameFirst

NameLast -1^ System

Administrator -2^ Product

Manager

Group By

• For lumping data together into groups.• All fields listed in SELECT part mustparticipate in the GROUP BY portionsomehow.• AS can be used to give computed field aname. These functions result in aggregatefields and are called aggregate functions.