The field table
.name
contains 'Stylus Photo 2100' and with the following query
SELECT `name` FROM `table` WHERE `name` LIKE '%Stylus 2100%'
I get no results. Of course i would if i searched
SELECT `name` FROM `table` WHERE `name` LIKE '%Photo 2100%'
How can I select the record by searching 'Stylus 2100' ?
Thanks
Also LIKE is much faster than REGEXP.
Basically, LIKE does very simple wildcard matches, and REGEX is capable of very complicated wildcard matches. In fact, regular expressions ( REGEX ) are so capable that they are [1] a whole study in themselves [2] an easy way to introduce very subtle bugs.
MySQL REGEXP performs a pattern match of a string expression against a pattern. The pattern is supplied as an argument. If the pattern finds a match in the expression, the function returns 1, else it returns 0. If either expression or pattern is NULL, the function returns NULL.
Well if you know the order of your words.. you can use:
SELECT `name` FROM `table` WHERE `name` REGEXP 'Stylus.+2100'
Also you can use:
SELECT `name` FROM `table` WHERE `name` LIKE '%Stylus%' AND `name` LIKE '%2100%'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With