Select*fromStudentWhereNameLIKE'%av%';+------"/> Select*fromStudentWhereNameLIKE'%av%';+------">

Home  >  Article  >  Database  >  MySQL How to find a string with a specified pattern within another string?

MySQL How to find a string with a specified pattern within another string?

PHPz
PHPzforward
2023-09-12 09:37:021103browse

MySQL 如何在另一个字符串中找到指定模式的字符串?

By using the LIKE operator and wildcard characters, we can find a string with a specified pattern in another string.

Syntax

LIKE specific_pattern

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

Example

Suppose we have a table called "student" which contains the names of students and we want to get the details of all students whose names contain the string "av" pattern . This can be done with the help of the 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 the wildcard character used with the LIKE operator.

The above is the detailed content of MySQL How to find a string with a specified pattern within another string?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete