SQL NOT operator is used in where clause along with other conditions and it is used to negate condition results. It means if any condition will return false, then the SQL NOT operator will turn it into true and the record will be displayed. Similarly, if the condition will return true then the NOT operator will convert it into false and the record will not be displayed.
SQL NOT Syntax
Select column1, column2,... columnN from table_name WHERE NOT condition;
Sample Table
Employee
Example
- Select all records from Employee table where DESIGNATION is not SDE II
SELECT * FROM Employee WHERE NOT DESIGNATION = 'SDE II';
- Select all records from Employee table where DESIGNATION is not SDE II AND salary is greater than 45000
SELECT * FROM Employee WHERE NOT DESIGNATION = 'SDE II' AND NOT SALARY < 45000;
This is how we can use SQL NOT operator
Hope you liked the article. If you have any doubts or concerns, please feel free to write us in comments or mail us at admin@codekru.com