Mazhar Hussain
Mazhar Hussain

Reputation: 125

WHERE CLAUSE multiple condition COMBINE AND OR in same Query NOT WORKING

SELECT *
FROM users
where user_id!='1' AND fast_name LIKE '%asim%'
   OR last_name LIKE '%asim%' OR CONCAT(fast_name,' ',last_name) LIKE '%asim%'

user 1=asim but he give me result asim why? however i am using userid not equal to and second thing is user_id must check and other condition are optional means only one condition accept with userid condition tell me what issue

Upvotes: 1

Views: 6439

Answers (1)

Jens
Jens

Reputation: 69440

You have to use brackets arround the or part:

SELECT *
FROM users
where user_id!='1' AND (fast_name LIKE '%asim%'
   OR last_name LIKE '%asim%' OR CONCAT(fast_name,' ',last_name) LIKE '%asim%')

Upvotes: 3

Related Questions