T-SQL – Difference Between <> All and Not In

t-sql

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)

Best Answer

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.