tags:

views:

20

answers:

3

Hello, I have a script to find the lowest value from a column but some entries dont have a value or its set to 0 if this is the case I'd like ti to find the next lowest value.

Here is my sql command.

$result = mysql_query("SELECT DISTINCT product_name, format, image_url, MIN(online_price), EAN FROM products where $searchstring and format = '{$cat}' AND EAN != ' ' AND EAN != '-' AND EAN != 'PRERELEASE' AND online_price > '0' group by EAN LIMIT " . ($page-1)*$Limit . ",$Limit");

Any ideas?

A: 

You can filter out the rows that you are not interested in and then find the lowest row from the rows remaining:

SELECT *
FROM products
WHERE -- your other conditions can go here --
AND online_price> 0
ORDER BY online_price
LIMIT 1 
Mark Byers
A: 

You are missing the AS clause:

MIN(online_price) AS minprice

You now have the result in minprice.

Sarfraz
A: 

Perhaps:

MIN(IF(online_price=0,NULL,online_price))
Wrikken