MySQL NOT
In MySQL, the NOT condition is used to negate a condition in SELECT, INSERT, UPDATE, and DELETE statements.
Syntax:
NOT condition;
Parameters:
condition: It is used to specify the conditions to negate.
Example 1: Using NOT with LIKE condition. Items table:
| ID | NAME | QUANTITY |
| 1 | Electronics | 30 |
| 2 | Sports | 45 |
| 3 | Fashion | 100 |
| 4 | Grocery | 90 |
| 5 | Toys | 50 |
Query:
SELECT name FROM items WHERE name NOT LIKE 'ElecOutput:
NAME Sports Fashion Grocery ToysExample 2: Using NOT with IN condition. Items table:
| ID | NAME | QUANTITY |
| 1 | Electronics | 30 |
| 2 | Sports | 45 |
| 3 | Fashion | 100 |
| 4 | Grocery | 90 |
| 5 | Toys | 50 |
Query:
SELECT * FROM items WHERE quantity NOT IN (30, 45, 50) ORDER BY name;
Output:
| ID | NAME | QUANTITY |
| 3 | Fashion | 100 |
| 4 | Grocery | 90 |