CodesJava

Easy learning with example program codes

NOT clause in MySQL

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 'Elec%';

Output:

NAME
Sports
Fashion
Grocery
Toys
4 rows  in set <0.05 sec>

Example 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
2 rows  in set <0.02 sec>
Please follow and like us:
error









Copyright © 2019 CodesJava DMCA.com Protection Status