In MySQL, how can we check whether a string of a specified pattern is not present within another string?


We can check whether a string of specified pattern is not present within another string by using NOT LIKE operator along with wildcard characters.

Syntax

NOT LIKE specific_pattern

Specific_pattern is the pattern of string we do not want to find out within another string.

Example

Suppose we have a table named ‘student’ having names of the students and we want to get the details of all those students which are not having a pattern of string ‘av’ within their names. It can be done with the help of following MySQL query:

mysql> Select * from Student WHERE name NOT LIKE '%av%';

+------+---------+---------+----------+--------------------+
| Id   | Name    | Address | Subject  | year_of_Admission  |
+------+---------+---------+----------+--------------------+
| 15   | Harshit | Delhi   | Commerce |               2009 |
| 21   | Yashraj | NULL    | Math     |               2000 |
+------+---------+---------+----------+--------------------+

2 rows in set (0.00 sec)

In the above example, the ‘%’ symbol is a wildcard used along with NOT LIKE operator.

Updated on: 07-Feb-2020

56 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements