The MySQL NOT LIKE Operator performs precisely the opposite of the Like that we discussed earlier. The Not Like operator returns the records whose values are not matching with a given pattern.
For this NOT LIKE operator and Wildcards demo, we used the below-shown data.
MySQL NOT LIKE Operator Example
In this example, we are using the percentage wildcard along with the Not Like operator. The following query returns all the Customers whose Occupation doesn’t start with M.
SELECT EmpID, `First Name`, `Last Name`, Qualification, Occupation, Income, Sales, HireDate FROM customer WHERE Occupation NOT LIKE 'M%';
This 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 customer WHERE Occupation NOT LIKE '%l';
NOT LIKE Example 2
In this example, we are using the underscore wildcard to match the single character. The below 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 customer WHERE Occupation NOT LIKE '_a%';
The following Not Like query selects the employees Whose Occupation starts with M, and the third letter or character should be n. Please refer Like Operator article.
SELECT EmpID, `First Name`, `Last Name`, Qualification, Occupation, Income, Sales, HireDate FROM customer WHERE Occupation NOT LIKE '%M_n%';
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 query examples using this Terminal.
SELECT 'a' NOT LIKE 'a', 'a' NOT LIKE ' a', 'a' NOT LIKE 'a ';
SELECT 'Suresh@' NOT LIKE 'Suresh_', 'Suresh@' NOT LIKE '%h_';
SELECT 'Suresh_Babu' NOT LIKE 'Suresh\_%';