外部連接

Oracle SQL 入門

Sara Billen

Instructor

三種外部連接

  1. LEFT OUTER JOIN
  2. RIGHT OUTER JOIN
  3. FULL OUTER JOIN
Oracle SQL 入門

Inner Join

Inner Join 只回傳符合的列

Left Outer Join

Left Join 回傳符合列與左表的列

Right Outer Join

Right Join 回傳符合列與右表的列

Full Outer Join

Full Join 回傳符合列與兩表的列

Oracle SQL 入門

Track 與 Invoice 表

Track and InvoiceLine Tables

  • 每張發票至少會對應 1 個曲目
  • 並非所有曲目都出現在發票中
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

Oracle SQL 入門

Customer 與 Employee 表

Customer and employee table

  • 每位顧客都有支援代表
  • 不是每位員工都是支援代表
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

Oracle SQL 入門

Customer 與 Employee 表

Customer and employee table

  • 並非每位顧客都有支援代表
  • 不是每位員工都是支援代表
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

Oracle SQL 入門

一起來練習吧!

Oracle SQL 入門

Preparing Video For Download...