views:

44

answers:

2

I have a table which has a column with numbers (no specific order).

What would be the shortest way to insert the minimal number in this column into $min variable in PHP ?

+5  A: 
list($min) = mysql_fetch_row(mysql_query('SELECT IFNULL(MIN(column), 0) FROM table'));

If you want something else than 0 returned when there are no rows, just edit the 2nd parameter of IFNULL. If there are guaranteed to be at least 1 row, or you want NULL when there are no rows, you can remove the IFNULL completely.

reko_t
A: 
SELECT MIN(column) FROM 'table'
Josso