If you are mixing AND and OR in your queries you need to group them into parenthesis
SELECT * FROM contact WHERE status = '1'
AND lower(concat(nume,' ',prenume)) LIKE '%test%'
AND (lower(concat(prenume,' ',nume)) LIKE '%test%'
OR functie LIKE '%test%'
OR email LIKE '%test%'
OR compartiment LIKE '%test%'
OR email LIKE '%test%'
OR user_sap LIKE '%test%'
OR atrib LIKE '%test%'
OR user_mtr LIKE '%test%'
OR interior LIKE '%test%'
OR mobil_firma LIKE '%test%')
ORDER BY nume, prenume LIMIT 7
simplypixie
Practically a Master Poster
642 posts since Oct 2010
Reputation Points: 157
Solved Threads: 118
Skill Endorsements: 5
OR will "reset" your where clause and start over if you don't use parenthesis - just like simplypixie said.
Basically it's like
where somecondition here
OR -- whatever happened before the OR doesn't matter
some other confition
OR -- same here, it doesn't matter what the first condition returned or what the second condition returned.
You can either type it like:
where status = '1' and lower(concat(nume, ' ' ,prenume)) LIKE '%test%'
and lower(concat(prenume, ' ' , nume)) LIKE '%test%'
or status = '1' and functie LIKE '%test%'
So basically repeat the whole set of criteria for every OR, or do it like simplypixie's example (which is how everybody does it). Basically you'll allow OR to "reset" only the conditions inside the parenthesis that the OR appears.
adam_k
Veteran Poster
1,057 posts since Jun 2011
Reputation Points: 274
Solved Threads: 205
Skill Endorsements: 11