【发布时间】:2018-07-06 09:21:19
【问题描述】:
我需要 Employee 表中 OwnerID 字段和 GMID 字段中具有空值的行。
SELECT b.FirstName + space(1) + b.LastName AS OwnerName,
c.FirstName + space(1) + c.LastName AS GeneralManager
FROM Store a
JOIN Employee b ON a.OwnerID = b.EmployeeID
JOIN Employee c ON a.GMID = c.EmployeeID
查询正在运行...但存储表的 OwnerID 和 GMID 字段中有空值。我还需要进行哪些更改才能恢复空行?
更新 这是更正后的查询。
SELECT b.FirstName + space(1) + b.LastName AS OwnerName,
c.FirstName + space(1) + c.LastName AS GeneralManager
FROM Store a
LEFT JOIN Employee b ON a.OwnerID = b.EmployeeID
LEFT JOIN Employee c ON a.GMID = c.EmployeeID
https://docs.microsoft.com/en-us/sql/t-sql/queries/from-transact-sql?view=sql-server-2017
【问题讨论】:
标签: sql tsql join left-join multiple-join-rows