Skip to content Skip to sidebar Skip to footer

Include Space In Mysql Like Search

I am having problem in using mysql like keyword in certain condition. My requirement goes like this. First, when i search for 'ABC', the result should find ABC and ABCdef but not

Solution 1:

'% heart%' doesn't work because you are asking for anything, plus space, plus heart, plus anything.

Try something like:

like'heart%'ORlike'% heart%'

Solution 2:

I just saw this old unsolved request. As someone may have the same question, I'll post the answer in spite of the request's age.

WHERE q.question LIKE'heart%'OR question LIKE'% heart%'AND q.question LIKE'liver%'OR q.question LIKE'% liver%'

translates to

WHERE q.question LIKE'heart%'OR (question LIKE'% heart%'AND q.question LIKE'liver%')
OR q.question LIKE'% liver%'

because AND has precedence over OR.

So one must use parentheses here. This is often the case when mixing AND and OR and it's good habit to always do so:

WHERE (q.question LIKE'heart%'OR question LIKE'% heart%')
AND (q.question LIKE'liver%'OR q.question LIKE'% liver%')

Solution 3:

what about

WHERE foo LIKE'% heart%'OR foo LIKE'heart%'

Post a Comment for "Include Space In Mysql Like Search"