NOT
NOT is a logical operator used in SQL to negate a condition, thereby reversing its output. If the condition after NOT evaluates to TRUE, NOT changes it to FALSE, and vice versa. NOT can be used in combination with other logical operators like AND and OR. It is often utilized in WHERE clause to filter data.
Example
Output
Explanation
In this example, the “NOT” statement is used in conjunction with the “WHERE” clause to display all records from the ‘Employees’ table where the gender is not ‘Male’. Thus, only ‘Female’ records are returned.
Example
Output
Explanation
The above query selects all records from the ‘orders’ table where ‘customer_id’ does not equal 1. The NOT
statement inverts the predicate (condition), the result is true if the predicate isn’t satisfied.
Example
Output
Explanation
In this SQL Server example, the query is searching for all employees whose department is not ‘Sales’. The NOT operator is used to exclude the records that do not meet the specified conditions.
Example
Output
Explanation
The SQL NOT
Operator is used to negate a condition in the WHERE
clause. In this example, it filters out records where Customers are not from Germany. The output displays all customers whose country is not ‘Germany’.
Example
Output
Explanation
The NOT
operator in SQL is used to filter the results of a query based on whether a certain condition is not met. In the example provided, the SELECT * FROM Employees WHERE NOT Position = 'Engineer'
query returns all rows where the position is not ‘Engineer’.