Home > Database > Mysql Tutorial > How to Find MySQL Records Containing Multiple Specific Words?

How to Find MySQL Records Containing Multiple Specific Words?

Barbara Streisand
Release: 2024-12-26 05:18:09
Original
556 people have browsed it

How to Find MySQL Records Containing Multiple Specific Words?

Finding Records with Multiple Words Using MySQL LIKE or REGEXP

The provided query using LIKE operator fails to match the record with the desired words. To address this, one can employ the REGEXP operator, which enables matching patterns within a string.

Using REGEXP:

The REGEXP operator can be used as follows:

SELECT `name` FROM `table` WHERE `name` REGEXP 'Stylus.+2100'
Copy after login

Here, 'Stylus. 2100' matches any string that begins with 'Stylus' followed by any number of characters, then '2100'. This will retrieve the desired record.

Using LIKE with Conjunction:

Alternatively, one can use the LIKE operator with a conjunction:

SELECT `name` FROM `table` WHERE `name` LIKE '%Stylus%' AND `name` LIKE '%2100%'
Copy after login

In this case, the query searches for records that contain both 'Stylus' and '2100' in any order.

The above is the detailed content of How to Find MySQL Records Containing Multiple Specific Words?. For more information, please follow other related articles on the PHP Chinese website!

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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template