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 xyzABCdef
or xyzABC
. It seems simple at first to use ABC%
. but in condition when i search for 'heart%'
, it doesnot return row that have 'liver heart'
because it returns only row that have heart
at the beginning of the string.Then i tried using % heart%
.This returned row having 'liver heart'
but not those rows that have heart at the beginning of string. I am kind of stuck here..so guys help me.
EDIT With your help guys i came with the following solution but still its giving me some problem.
SELECT q.question_id, q.question, q.date,p.fname,p.lname,p.phys_id,
p.pic_path
FROM questions q JOIN physiciansprofile p ON p.phys_id=q.phys_id
WHERE q.question LIKE 'heart%' OR question LIKE '% heart%'
AND q.question LIKE 'liver%' OR q.question LIKE '% liver%'
ORDER BY q.date DESC LIMIT 0,10;
But this query return heart failure
and symptoms liver
as well.Is there any solution for this. I need to get result containing both heart
and liver
and also must satisfy condition as stated before. Is there any to solve this
'% heart%' doesn't work because you are asking for anything, plus space, plus heart, plus anything.
Try something like:
like 'heart%' OR like '% heart%'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With