- 实质上是Customers表有这条数据,而Orders表没有这条数据的问题;
- 或者转变为另一个思路,就是转换为字段有无的思路,CustomerId在Customers表有,在Orders表无;
- 第一种,表之间数据有无的问题,尤其是像上面这种状况,完全可以用left join + is null来解决;大的数据集作为主表,小的数据集为辅表,挑选出在辅表里面没有的数据就好;
select a.Name as Customers from Customers a left join Orders b on a.id = b.CustomerId where b.id is null;
- 第二种,字段作为where限制条件;就是提前把小数据集的表某个字段筛选出来,用大数据集对应字段值来找差值;
select a.Name as Customers from Customers a where a.id not in (select CustomerId from Orders )
- 总的来说这类问题可以有两种思路,一种是从表的维度去思考,一种是从表中字段的维度去思考;



