Multiple LIKE, OR MySql Queries Match

Posted by Codex73 on Stack Overflow See other posts from Stack Overflow or by Codex73
Published on 2011-11-16T01:42:44Z Indexed on 2011/11/16 1:51 UTC
Read the original article Hit count: 158

Filed under:
|

Search for: 'chemist'

Problem: query which will match a string like 'onechemist' but not 'chemist'.

SELECT id,name FROM `records` 
WHERE name LIKE '%". mysql_real_escape_string($q) ."%' 

This alternate try won't work:

SELECT id,name FROM `records` 
WHERE name LIKE '%". mysql_real_escape_string($q) ."%'  
OR name LIKE '". mysql_real_escape_string($q) ."%' 
OR name LIKE '%". mysql_real_escape_string($q) ."'

How could I compile the above into one single query that will match any field which has the string or optimize the query into a better expression?

© Stack Overflow or respective owner

Related posts about mysql

Related posts about sql