外连接

Oracle SQL 入门

Sara Billen

Instructor

三种外连接

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

内连接

内连接 仅返回匹配的行

左外连接

左连接 返回匹配行和左表的行

右外连接

右连接 返回匹配行和右表的行

全外连接

全连接 返回匹配行和两表的行

Oracle SQL 入门

Track 与 Invoice 表

Track 与 InvoiceLine 表

  • 每张发票至少包含一首曲目
  • 并非所有曲目都出现在发票中
Oracle SQL 入门

左外连接

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

左外连接输出

Oracle SQL 入门

客户表与员工表

客户表与员工表

  • 每位客户都有客服代表
  • 并非每位员工都是客服代表
Oracle SQL 入门

右外连接

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

右外连接输出

Oracle SQL 入门

客户表与员工表

客户表与员工表

  • 并非每位客户都有客服代表
  • 并非每位员工都是客服代表
Oracle SQL 入门

全外连接

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

全外连接查询输出

Oracle SQL 入门

Passons à la pratique !

Oracle SQL 入门

Preparing Video For Download...