Reputation: 973
I have three categories & subcategories in table. Category (adventure, rejuvenation, gourmet) AND sub_category(air, balloon etc.)
Now I am firing below query
select * from products where sub_category Like '%Air%' or
sub_category Like '%Land%' and category = 'adventure'
and type = 'experience' and status = 'active'
Now problem is it is also getting rows where category = Rejuvenation. Hence it should only get result where category = adventure
Upvotes: 0
Views: 32
Reputation: 622
AND has priority over OR. That's why your query returns everything, that has a sub category like Air. You should update your query like this:
select * from products where (sub_category Like '%Air%' or
sub_category Like '%Land%') and category = 'adventure'
and type = 'experience' and status = 'active'
Upvotes: 0
Reputation: 69440
You have to use brackets arround the or Statements:
select * from products where (sub_category Like '%Air%' or
sub_category Like '%Land%' )and category = 'adventure'
and type = 'experience' and status = 'active'
Upvotes: 4