Reputation: 3524
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?
Upvotes: 2
Views: 2287
Reputation: 125985
What is the difference?
The regular expression
(a.name REGEXP '( )*(*my*)*( )*(*donuts*)( )*')
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:
(a.name REGEXP '( )*(my*)*( )*(donuts*)( )*')
This matches any a.name
with:
zero or more occurrences of:
m
, followed byy
followed by
donut
, followed bys
, followed by
The simple pattern
a.name LIKE '%*my*%' AND a.name LIKE '%*donuts*%'
This matches any a.name
with:
*my*
, followed byand with:
*donuts*
, followed byUpvotes: 4