what is the best way to write a query that combines AND , OR without any interference
for example
sql= " select * from table where category=5 AND itme_name LIKE %$x% OR item_detail LIKE %x% " ;
waht i want is something like
category=5 AND ( itme_name LIKE %$x% OR item_detail LIKE %$x% )
ican do this by using 2 query
OR SOMETHING LIKE
select * from table where category=5 AND category IN(
select category from table where itme_name LIKE %$x% OR item_detail LIKE %x% )
but i wonder if i can do this without that inner query by i dont know maybe using Parenthesis around second part?
Use parentheses to change the precedence (without parentheses AND has higher precedence than OR):
Notes:
itme_nameis most likely incorrectly spelled. It probably should beitem_name. You may also need to fix the table definition and all other queries that use the incorrect spelling.