I have a table CANDIDATE in my db which is running under MySQL 5.5 and I am trying to get rows from table where RAM is contains in firstname, so I can run below two queries, but I would like to now which query we should use for long term with respect to optimization.
SELECT * FROM CANDIDATE c WHERE firstname REGEXP 'ram';
SELECT * FROM CANDIDATE c WHERE firstname LIKE'%ram%';
REGEXP
and LIKE
are used to totally different cases.
LIKE
is used to add wildcards to a string whereas REGEXP
is used to match an attribute with Regular Expressions.
In your case a firstname
is more likely to be matched using LIKE
than REGEXP
and hence, it will be more optimized.