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

MySQLMySQLi Database

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.

raja
Published on 20-Feb-2018 10:12:56
Advertisements