sql - Why direct column value comparison is not evaluating after multiple like clause in mysql -


i have search query following:

select p.product_id, p.product_title,p.product_long_description    products p      p.product_title            '%t-shirt01%'      or  p.product_long_description '%t-shirt01%'     ,  p.product_status='active' 

in case last p.product_status='active' not evaluating. can explain logical reason not evaluating last comparison.

you should use brackets around or condition:

select p.product_id, p.product_title,p.product_long_description    products p      (p.product_title            '%t-shirt01%'         or  p.product_long_description '%t-shirt01%')        ,  p.product_status='active' 

your current solution filter non-active products match solution (title). , active ones has t-shirt01 in description.

the sql parser works cheap chinese calculators, starts first one:

does title contains t-shirt? yes -> lets show row.

no -> description contains t-shirt? yes -> active? -> yes -> lets show row. if doesn't contains t-shirt in description and/or inactive won't show row.

however adding brackets () yo can change evaluation. in math * +. in boolean and/or equivalent.


Comments

Popular posts from this blog

Why can rails not find a route created by a helper? -

javascript - jquery or ashx not working -

php - Redirect and hide target URL -