MySQL NOT LIKE Operator

The MySQL NOT LIKE Operator performs precisely opposite to the Like Operator. The Not Like operator returns the records whose values are not matching with a given pattern.

For this MySQL NOT LIKE operator and Wildcards demo, we used the below-shown data.

MySQL NOT LIKE Operator 1

MySQL NOT LIKE Operator Example

In this MySQL example, we are using the percentage wildcard along with the Not Like operator. The following MySQL query returns all the Customers whose Occupation doesn’t start with M.

SELECT EmpID, 
`First Name`,
      `Last Name`,
      Qualification,
      Occupation,
      Income,
      Sales,
      HireDate
FROM `MySQL Tutorial`.customer
WHERE Occupation NOT LIKE 'M%';
MySQL NOT LIKE Operator 2

This MySQL Not Like query shows the Employees whose Occupation doesn’t end with l.

SELECT EmpID, 
`First Name`,
      `Last Name`,
      Qualification,
      Occupation,
      Income,
      Sales,
      HireDate
FROM `MySQL Tutorial`.customer
WHERE Occupation NOT LIKE '%l';
MySQL NOT LIKE Operator 3

MySQL NOT LIKE Example 2

In this example, we are using the underscore wildcard to match the single character. The below MySQL Not like query returns the employees whose Occupation doesn’t contain the second letter as a.

SELECT EmpID, 
`First Name`,
      `Last Name`,
      Qualification,
      Occupation,
      Income,
      Sales,
      HireDate
FROM `MySQL Tutorial`.customer
WHERE Occupation NOT LIKE '_a%';
MySQL NOT LIKE Operator 4

The following Not Like query select the employees Whose Occupation starts with M and third letter or character should be n. Please refer Like Operator article.

SELECT EmpID, 
`First Name`,
      `Last Name`,
      Qualification,
      Occupation,
      Income,
      Sales,
      HireDate
FROM `MySQL Tutorial`.customer
WHERE Occupation NOT LIKE '%M_n%';
MySQL NOT LIKE Operator 5

MySQL NOT LIKE Operator Command Prompt Example

This example shows you the use of Not Like from the command prompt. You can also use any of the above MySQL example query using this Terminal.

SELECT 'a' NOT LIKE 'a', 'a' NOT LIKE ' a', 'a' NOT LIKE 'a ';

SELECT '[email protected]' NOT LIKE 'Suresh_', '[email protected]' NOT LIKE '%h_';

SELECT 'Suresh_Babu' NOT LIKE 'Suresh\_%';
MySQL NOT LIKE Operator 6