Outer joins

Introduction to Oracle SQL

Sara Billen

Instructor

Three types of outer joins

  1. LEFT OUTER JOIN
  2. RIGHT OUTER JOIN
  3. FULL OUTER JOIN
Introduction to Oracle SQL

Inner Join

Inner Join Returns matched rows only

Left Outer Join

Left Join Returns matched rows and left table's rows

Right Outer Join

Right Join Returns matched rows and right table's rows

Full Outer Join

Full Join Returns matched rows and both tables' rows

Introduction to Oracle SQL

Track and invoice tables

Track and InvoiceLine Tables

  • Every invoice refers to at least one track
  • Not all tracks are in an invoice
Introduction to Oracle SQL

Left outer join

SELECT t.TrackId, t.Name, i.InvoiceId, i.Quantity
  FROM Track t LEFT OUTER JOIN InvoiceLine i
  USING (TrackId)

Left outer join output

Introduction to Oracle SQL

Customer and employee tables

Customer and employee table

  • Every customer has a support rep
  • Not every employee is a support rep
Introduction to Oracle SQL

Right outer join

SELECT c.CustomerId, c.SupportRepId, e.FirstName, e.LastName, e.Title
FROM Customer c RIGHT OUTER JOIN Employee e
    ON c.SupportRepId = EmployeeId

Right outer join output

Introduction to Oracle SQL

Customer and employee tables

Customer and employee table

  • Not every customer has a support rep
  • Not every employee is a support rep
Introduction to Oracle SQL

Full outer join

SELECT c.CustomerId, c.SupportRepId,e.FirstName, e.LastName, e.Title
  FROM Customer c FULL OUTER JOIN Employee e
  ON c.SupportRepId = EmployeeId

Full Outer Join Query Output

Introduction to Oracle SQL

Let's practice!

Introduction to Oracle SQL

Preparing Video For Download...