MySQL Wildcards

MySQL Wildcards

MySQL Aliases

MySQL Aliases

MySQL Data Types

MySQL Data Types

MySQL Interview Questions

MySQL Interview Questions and Answers


MySQL Not Operator

In MySQL NOT operator is used to negate a condition in a SELECT, INSERT, UPDATE or DELETE statement. In other words, MySQL NOT condition is opposite of MySQL IN condition, it is fetch a record if the condition(s) is NOT TRUE.

MySQL NOT OPERATOR Syntax

To reduce the use of multiple OR conditions, use the following syntax:

Syntax

SELECT col1, col2, ...
FROM tablename
WHERE NOT condition;

Parameters:

tablename: The table name from which you want to perform NOT operator.

condition: Specifies the conditions that you want to negate.

MySQL NOT OPERATOR example

The following MySQL, NOT operator is used to fetch a records if the condition(s) is NOT TRUE:

Example

SELECT firstName, lastName, address FROM tblCustomerLoan
WHERE NOT firstName = 'Dilip';

Note:

In the above example, we are performing NOT operator to fetch a records if the condition(s) is NOT TRUE.

You can use MySQL Command Line Client to perform NOT operator to negate a condition. It will look like this:

MySQL NOT OPERATOR example with IN operator

The following MySQL, NOT operator is used with IN operator to fetch a records if the condition(s) is NOT TRUE, then the IN operator will evaluate to true:

Example

SELECT firstName, lastName, address FROM tblCustomerLoan
WHERE firstName NOT IN ('Yogesh', 'Mahesh');

Note:

In the above example, we are performing NOT operator with IN operator to fetch a records if the condition(s) is NOT TRUE.

You can use MySQL Command Line Client to perform NOT operator with IN operator to negate a condition. It will look like this: