Home > Database > Mysql Tutorial > 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
Release: 2023-09-12 09:37:02
forward
1200 people have browsed it

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
Copy after login

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)
Copy after login

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!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template