Ste
Ste

Reputation: 1520

Select Price range - MySQL Query

I need to select a price range from 0 to 50 euros.

I have this query:

SELECT * FROM products WHERE price >= 0 AND price <= 50;

Is there a better way to do it?

Upvotes: 0

Views: 14312

Answers (3)

Purnendu Sarkar
Purnendu Sarkar

Reputation: 342

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'

Upvotes: 0

Pekka
Pekka

Reputation: 449395

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 <.

Upvotes: 8

Pentium10
Pentium10

Reputation: 207838

SELECT * FROM products WHERE price BETWEEN 0 AND 50;

Upvotes: 0

Related Questions