How to obtain the minimum value of the MYSQL field

Source: Internet
Author: User
How to calculate the minimum value of the MYSQL field <;? Phprequire ('dbconnect. php'); $ query1 = & quot; SELECTmin (score) FROMtest & quot; & nbsp; $ result1 = mysql_query (& q how to calculate the minimum value of the MYSQL field
Require ('dbconnect. php ');
$ Query1 = "SELECT min (score) FROM test ";
$ Result1 = mysql_query ("$ query1") or die (mysql_error ());
$ Row1 = mysql_fetch_array ($ result1 );
Print_r ($ row1 );
?>
However, the following sentence is printed:
Array ([0] => 1 [min (score)] => 1)
It's far from what I want. how is it right?

------ Solution --------------------
Mysql_fetch_array (data, array_type)
Parameter description
Data is optional. Specifies the data pointer to be used. This data pointer is produced by the mysql_query () function.
Array_type
Optional. Specifies the result to be returned. Possible values:
MYSQL_ASSOC-associated array
MYSQL_NUM-number array
MYSQL_BOTH-default. Generate join and numeric arrays at the same time
You need to set the second parameter.
------ Solution --------------------
SELECT * FROM test where score = min (score );
------ Solution --------------------
You can take the entire line.
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 result is what you want.

------ Solution --------------------
In addition, if the minimum data obtained from this table is to be transferred to another table, you can create a stored procedure or create a view. Read the manual for yourself.

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.