8

Could you please tell me the differences between

select CustomerId from Customer Where TerritoryId <> All(select TerritoryId from Salesperson)

select CustomerId from Customer where TerritoryId NOT IN (select TerritoryId from Salesperson)
ypercubeᵀᴹ
  • 97,895
  • 13
  • 214
  • 305
June
  • 298
  • 1
  • 4
  • 15

1 Answers1

8

There is no difference in result but there is a bit different semantics.

X [comparison] ALL(set) mean that set is empty or the comparison is TRUE for each entry in the set.

X NOT IN (set) means that X does not belong to the set.

While [comparison] is "not equal", both forms are equivalent. But for other comparisons it may be different.

Martin Smith
  • 84,644
  • 15
  • 245
  • 333
Kondybas
  • 4,323
  • 15
  • 13