SUN SUN - 1 month ago 5x
SQL Question

MySQL Query not getting accurate output

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


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'