How to find the minimum value for MySQL field
Require (' dbconnect.php ');
$query 1 = "Select min (score) from Test";
$result 1 = mysql_query ("$query 1") or Die (Mysql_error ());
$row 1 = mysql_fetch_array ($result 1);
Print_r ($row 1);
?>
But print out the following words
Array ([0] = 1 [min (score)] = 1)
And I want the result is very poor, oh, how exactly write is right?
------Solution--------------------
Mysql_fetch_array (Data,array_type)
Parameter description
Data is optional. Specifies the data pointers to be used. The data pointer is the result of the mysql_query () function.
Array_type
Optional. Specifies what kind of results to return. Possible values:
MYSQL_ASSOC-Associative arrays
Mysql_num-numeric array
Mysql_both-Default. Simultaneous generation of associative and numeric arrays
You need to set a second parameter.
------Solution--------------------
SELECT * FROM Test where score=min (score);
------Solution--------------------
If you take the whole line, you can
SELECT * FROM Test where score=min (score);
Or
SELECT * FROM Test order by score ASC limit 1;
..
------Solution--------------------
SELECT min (field 1) as Min_ field 1,min (Field 2) as Min_ field 2,min (Field 3) as Min_ field 3,min (Field 4) As Min_ field 4,from table where
The results are what you want.
------Solution--------------------
To add, if the minimum data obtained from this table is to be dumped into another table, you can create a stored procedure or create a view. Go and see the Manual for yourself.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.