假设我有一个Contract
包含以下字段的合同表:ContractId
, ProductID
, ProductType
。在相同的表中,ContractId
我有两种可能ProductID
。所有表格都填充了两个可能的ProductType
:Type1
和Type2
.
以一种方式或另一种方式执行以下查询的原因是什么?
方式一:
select c1.ProductID, c2.ProductID
from Contract as c1 left join Contract as c2 on c1.ContractId=c2.ContractId
where c1.ProductType <>'Type2'
方式二:
select c1.ProductID, c2.ProductID
from Contract as c1 left join Contract as c2 on c1.ContractId=c2.ContractId
where c1.ContractId not in (select ContractId from Contract where ProductType = 'Type2')
感谢您的聪明回答!