How to use the NOT Operator in SQL
The SQL NOT operator allows you to exclude specific rows from the results of a query, giving you more control over the data you retrieve. Excluding unwanted data can make your queries run more efficiently and faster.
The NOT operator negates a condition and returns TRUE if the condition is FALSE.
SELECT * FROM products WHERE NOT category = 'dresses';
In this example, the NOT operator negates the condition, so only the products that do not belong in the ‘dresses’ category will be returned.
SELECT * FROM products WHERE NOT price > 10 AND quantity IS NULL;
In this example, we combined the operators to return the products that cost less than 10 and does have an empty value for quantity.