Select Price range - MySQL Query
I need to select a price range from 0 to 50 euros.
开发者_StackOverflow中文版I have this query:
SELECT * FROM products WHERE price >= 0 AND price <= 50;
Is there a better way to do it?
There is BETWEEN
:
SELECT * FROM products WHERE price BETWEEN 0 AND 50;
but its behaviour is different. It selects values that are equal to the starting points as well, so >=
instead of >
and <=
instead of <
.
SELECT * FROM products WHERE price BETWEEN 0 AND 50;
price value pass
$pricerange = explode('-', str_replace('$','',$searchValue['price_range']));
select * from tableName where model='".$searchValue['model']."' and (price BETWEEN $pricerange[0] and $pricerange[1]) and status='active'
精彩评论