Cheap VPS & Xen Server


Residential Proxy Network - Hourly & Monthly Packages

MySQL NOT


The MySQL NOT condition is opposite of MySQL IN condition. It is used to negate a condition in a SELECT, INSERT, UPDATE or DELETE statement.

Syntax:

  1. NOT condition

Parameter

condition: It specifies the conditions that you want to negate.

MySQL NOT Operator with IN condition

Consider a table “officers”, having the following data.

mysqlnot1

Execute the following query:

  1. SELECT *
  2. FROM officers
  3. WHERE officer_name NOT IN (‘Ajeet’,‘Vimal’,‘Deepika’);

Output:

mysqlnot2

 

MySQL NOT Operator with IS NULL condition:

Execute the following query:

  1. SELECT *
  2. FROM officers
  3. WHERE officer_name IS NOT NULL;

Output:

mysqlnot3

MySQL NOT Operator with LIKE condition:

We are taking the same table “officer” for this operation also:

Execute the following query:

  1. SELECT *
  2. FROM officers
  3. WHERE officer_name NOT LIKE ‘A%’;

Output:

mysqlnot4

 

MySQL NOT Operator with BETWEEN condition:

We are taking the same table “officer” for this operation also:

Execute the following query:

  1. SELECT *
  2. FROM officers
  3. WHERE officer_id NOT BETWEEN 3 AND 5;

Output:

mysqlnot5

Comments

comments