How it is possible in MySQL to find a string of specified pattern within another string?

MySQLMySQLi Database

We can find a string of specified pattern within another string by using LIKE operator along with WILDCARDS.


LIKE specific_pattern

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


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 having the pattern of string ‘av’ within their names. It can be done with the help of following MySQL query −

mysql> Select * from Student Where Name LIKE '%av%';

| Id   | Name   | Address | Subject   |
| 1    | Gaurav | Delhi   | Computers |
| 2    | Aarav  | Mumbai  | History   |
| 20   | Gaurav | Jaipur  | Computers |

3 rows in set (0.00 sec)

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

Updated on 04-Feb-2020 06:00:45