【发布时间】:2020-09-25 11:23:26
【问题描述】:
假设我在 SQL Server 中有这些表:
tbl_Applicants
ID | name | typeid | depid
---+------+--------+-------
1 | Mark | 1 | NULL
2 | Ted | 2 | 1
tbl_ApplicantType
ID | Type
---+----------
1 | Student
2 | Employee
tbl_Department
ID | department_name
---+----------------
1 | Finance
2 | HR
我想加入表格以便得到下面的结果
这是我想要的结果:
Name | type | department
-----+----------+---------------
Mark | Student | NULL
Ted | Employee | HR
我有这个选择语句:
select
a.name, b.type, c.department_name
from
tbl_applicants a, tbl_ApplicantType b, tbl_Department c
where
a.depid = c.ID and a.typeid = b.ID
这是我现在得到的结果:
Name | type | department
-----+----------+------------
Ted | Employee | HR
知道如何在包含空值的地方实现我想要的结果吗?
【问题讨论】:
-
使用正确的
JOIN语法,改成LEFT JOIN更容易
标签: sql sql-server join