使用not in:
select a.* from HRPersonnel as a
where a.unitid=25
and PersonnelId not in
(select PersonnelId from HRSalaryDeploy )
始终查询不出来数据,但是括号中的数据集PersonnelId 和左侧的的确有差异。
查了查发现:当not in 的子集中存在null值的时候,返回的结果肯定是null,所以我查不出数据
这个时候就要使用not exists :
select a.* from HRPersonnel as a
where a.unitid=25
and not exists
(select PersonnelId from HRSalaryDeploy as b where a.PersonnelId=b.PersonnelId )