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


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

Syntax

LIKE specific_pattern

Specific_pattern is the pattern of string we 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 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

59 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements