MySQL: how to return the maximum value of a field from a table?

The simplest example, if possible, give.


Answer 1, authority 100%

<?php
$row = mysql_fetch_object(mysql_query("select max(`field`) as `myname_of_var` from `table`"));
print($row->myname_of_var);

In general, use frameworks


Answer 2, authority 50%

  MAX ()  -

documentation


Answer 3, authority 50%

select max(`field`) from `table`

upd

$db=new PDO($dsn, $user, $password);
$req=$db->prepare("select max(`field`) from `table`");
$req->execute();
$max=current($req->fetch());
echo '$max=',$max;

Leave a reply

Please enter your comment!
Please enter your name here