'LIKE ('%this%' OR '%that%') and something=else' not working 'LIKE ('%this%' OR '%that%') and something=else' not working mysql mysql

'LIKE ('%this%' OR '%that%') and something=else' not working


It would be nice if you could, but you can't use that syntax in SQL.

Try this:

(column1 LIKE '%this%' OR column1 LIKE '%that%') AND something = else

Note the use of brackets! You need them around the OR expression.
Without brackets, it will be parsed as A OR (B AND C),which won't give you the results you expect.


Instead of using LIKE, use REGEXP. For example:

SELECT * WHERE value REGEXP 'THIS|THAT'
mysql> SELECT 'pi' REGEXP 'pi|apa';                     -> 1mysql> SELECT 'axe' REGEXP 'pi|apa';                    -> 0mysql> SELECT 'apa' REGEXP 'pi|apa';                    -> 1mysql> SELECT 'apa' REGEXP '^(pi|apa)$';                -> 1mysql> SELECT 'pi' REGEXP '^(pi|apa)$';                 -> 1mysql> SELECT 'pix' REGEXP '^(pi|apa)$';                -> 0

Refer:http://dev.mysql.com/doc/refman/5.1/en/regexp.html


Try something like:

WHERE (column LIKE '%this%' OR column LIKE '%that%') AND something = else