Home >Database >Mysql Tutorial >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'
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%'
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!