mysql use like with multiple values

Post Reply
mister_v
Posts: 188
Joined: Thu Mar 04, 2010 9:19 pm

mysql use like with multiple values

Post by mister_v »

Hello,

I having a query that has to search multiple values:

Code: Select all

SELECT id,name FROM table WHERE name LIKE '%value1%' OR name LIKE '%value2%' OR name LIKE '%value3%' 
I'm wondering if there isn't a faster way?
Something like

Code: Select all

SELECT id,name FROM table WHERE name LIKE IN ('%value1%','%value2%','%value%')
But this doesn't work, it only works if you search the full value, not part of string.
chris
Site Admin
Posts: 194
Joined: Mon Jul 21, 2008 9:52 am

Re: mysql use like with multiple values

Post by chris »

You can use REGEXP.

Code: Select all

SELECT id,name FROM table WHERE name REGEXP 'value1 | value2 | value3'
It should work.
Post Reply