It looks like "LIKE" is only slightly faster(on my XP), hardly worth
mentioning. Go with what is easier for you to read or for portability if
you need it. IMHO

set @a='gfdueruie baz hdhrh';select BENCHMARK(5000000, (select 1 from
dual WHERE @a LIKE '%foo%' OR @a LIKE '%bar%' OR @a LIKE '%baz%')) as
elapse_time;
# average 750ms


set @a='gfdueruie baz hdhrh';select BENCHMARK(5000000, (select 1 from
dual WHERE @a REGEXP 'foo|bar|baz' != 0)) as elapse_time;
# average 770ms 


Ed

-----Original Message-----
From: Morten Primdahl [mailto:[EMAIL PROTECTED] 
Sent: Friday, August 15, 2008 5:12 AM
To: mysql
Subject: REGEXP vs LIKE/OR


Hi,

I want to retrieve all records where the field "value" contains either  
"foo", "bar" or "baz". Like so:

SELECT id FROM table WHERE value LIKE '%foo%' OR value LIKE '%bar%' OR  
value LIKE '%baz%';

But then I stumbled upon REGEXP, and can do the same this way:

SELECT id FROM table WHERE value REGEXP 'foo|bar|baz' != 0;

Any opinions on what's the better approach and why?

Thanks

Morten





-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:
http://lists.mysql.com/[EMAIL PROTECTED]


--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]

Reply via email to