Reputation: 123
Not able to solve this query:
Want to search product with category, subcategory , lower price range and upper price range
select * from product p join category c
ON(p.category_id=c.category_id) where p.category=? and p.sub_category_id=?
and lower_price_limit between ? and ? or upper_price_limit between ? and ?
For example: A product range from 200 to 250
and pass 220 to 230
this doesn't work.
Thanks
Upvotes: 0
Views: 668
Reputation: 1891
select *
from product p
join category c ON p.category_id=c.category_id
where p.category=? and p.sub_category_id=? and
(lower_price_limit between ? and ? or upper_price_limit between ? and ?)
Upvotes: 0
Reputation: 31879
You forgot to add parenthesis on your WHERE
clause:
SELECT *
FROM product p
JOIN category c
ON p.category_id = c.category_id
WHERE
p.category = ?
AND p.sub_category_id = ?
AND (
lower_price_limit BETWEEN ? AND ?
OR upper_price_limit BETWEEN ? AND ?
)
Upvotes: 1
Reputation: 6661
Try this query :-
select * from product p join category c
ON p.category_id=c.category_id where p.category=? and p.sub_category_id=?
and (lower_price_limit between ? and ? or upper_price_limit between ? and ?)
Upvotes: 0