Outer joins

Introduzione a Oracle SQL

Sara Billen

Instructor

Tre tipi di outer join

  1. LEFT OUTER JOIN
  2. RIGHT OUTER JOIN
  3. FULL OUTER JOIN
Introduzione a Oracle SQL

Inner Join

Inner Join Restituisce solo le righe abbinate

Left Outer Join

Left Join Restituisce le righe abbinate e quelle della tabella sinistra

Right Outer Join

Right Join Restituisce le righe abbinate e quelle della tabella destra

Full Outer Join

Full Join Restituisce le righe abbinate e quelle di entrambe le tabelle

Introduzione a Oracle SQL

Tabelle di brani e fatture

Tabelle Track e InvoiceLine

  • Ogni fattura fa riferimento ad almeno un brano
  • Non tutti i brani compaiono in una fattura
Introduzione a Oracle SQL

Left outer join

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

Risultato left outer join

Introduzione a Oracle SQL

Tabelle di clienti e dipendenti

Tabelle Customer ed Employee

  • Ogni cliente ha un support rep
  • Non ogni dipendente è un support rep
Introduzione a 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

Risultato right outer join

Introduzione a Oracle SQL

Tabelle di clienti e dipendenti

Tabelle Customer ed Employee

  • Non ogni cliente ha un support rep
  • Non ogni dipendente è un support rep
Introduzione a 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

Risultato full outer join

Introduzione a Oracle SQL

Esercitiamoci!

Introduzione a Oracle SQL

Preparing Video For Download...