SUN SUN - 1 year ago 118
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

Answer Source

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'
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download