I have a mySQL wildcard query that isn’t working probably because I use InnoDB instead of MyISAM.
SELECT a.product_id, a.category_id FROM products a
LEFT JOIN users u ON u.userid=a.ownerid
WHERE a.active=1 AND a.approved=1
AND a.deleted=0 AND a.name LIKE '%*my*%'
AND a.name LIKE '%*donuts*%'
AND (a.name REGEXP '( )*(*my*)*( )*(*donuts*)( )*')
It works fine whenever a word is used instead of a wildcard, that’s not the problem.
I’m just wondering, is the part of
(a.name REGEXP '( )*(*my*)*( )*(*donuts*)( )*')
really needed after already doing a
LIKE '%*my*%' AND a.name LIKE '%*donuts*%'
What is the difference?
The regular expression
This produces an error, because a quantifier (e.g. an unescaped
*character) is not valid at the start of a group (i.e. immediately after an unescaped(character). Ignoring the two times where that occurs yields:This matches any
a.namewith:zero or more occurrences of:
m, followed byyfollowed by
donut, followed bys, followed byThe simple pattern
This matches any
a.namewith:*my*, followed byand with:
*donuts*, followed by