I am stuck on range search query. Please see this below examples :
SELECT * FROM product where status='A' and subcat_id=5 AND product.price < 50 AND product.price BETWEEN 50 AND 100 AND category = "male"
In above example , it does not returns records below 50 yet they are in database.
If I try as in second example below :
SELECT * FROM product where status='A' and subcat_id=5 AND product.price < 50 OR product.price BETWEEN 50 AND 100 AND category = "male"
It returns all records which not under male category but less then 50
Finally I want to get records which are in range less then 50 or between 50 to 100 but only for male category.
Thanks for your advice.
ANDhas higher precedence thanOR. Your query is interpreted as follows:You need to insert parentheses in the appropriate place to group the terms correctly. The only remaining question is precisely where to put them.
I think you mean this:
This will show products under 50 for all categories, and products between 50 and 100 for the category male.