I have a SQL Database that has a column like this:
ID
-----
0352
5432
4382
3520
30593
3992
295
What I want to do is search through that column, find the largest number (30593) and store it in a variable.
This database has other columns, the example above is for demonstration only.
eg
$largestNumber = GET LARGEST NUMBER FROM ID
How would I do that in PHP / MySQL
In PHP, we do it like this:
$rowSQL = mysql_query( "SELECT MAX( ID ) AS max FROM `tableName`;" );
$row = mysql_fetch_array( $rowSQL );
$largestNumber = $row['max'];
我相信SELECT max(id) FROM table
会起作用。
试试这个查询
"SELECT MAX(Price) AS HighestPrice FROM Products";
SELECT MAX(ID) FROM TABLE
执行该语句并将其分配给您的变量。
You can do a single query to figure this out:
http://www.tutorialspoint.com/mysql/mysql-max-function.htm
MySql has it's own Max function that will return the highest value in the specified column.
使用MAX(ID)
获得最大值
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.