Using NOT operator to inverse the condition in SQL Server

Imagine a scenario where you want to retreive records that you dont want. You can use the NOT operator to reverse the search condition.

For example , You want to get all the departments having the GroupName other than ‘Research and Development’.

SELECT * FROM HumanResources.Department
where NOT ( GroupName = 'Research and Development' )
Using NOT operator to inverse the condition in SQL Server

The other way of getting the same result is using the != in every condition.

SELECT * FROM HumanResources.Department
where  GroupName != 'Research and Development'
%d bloggers like this: