MySQL Max Function

Submitted by:Andery Smith

Date added:31 December, 2011

Category:MySQL

MySQL's MAX aggregate function will find the largest value in a group. here shown an example

Tags: max function

Code Snippet:

<?php
// Make a MySQL Connection

$query = "SELECT type, MAX(price) FROM products GROUP BY type";

$result = mysql_query($query) or die(mysql_error());

// Print out result
while($row = mysql_fetch_array($result)){
echo "The most expensive ". $row['type']. " is $" .$row['MAX(price)'];
echo "<br />";
}
?>
 
 

Comments