How to skip an empty LIKE operator in a multiple LIKE query?
Posted
by alex
on Stack Overflow
See other posts from Stack Overflow
or by alex
Published on 2010-03-04T14:08:56Z
Indexed on
2010/04/06
20:23 UTC
Read the original article
Hit count: 166
mysql
I notice my query doesn't behave correctly if one of the like variables is empty:
SELECT name
FROM employee
WHERE name LIKE '%a%'
AND color LIKE '%A%'
AND city LIKE '%b%'
AND country LIKE '%B%'
AND sport LIKE '%c%'
AND hobby LIKE '%C%'
Now when a and A are not empty it works but when a, A and c are not empty the c part is not excuted so it seems?
How can I fix this?
© Stack Overflow or respective owner