Forum : How do I find second highest value from a table?
Brief description  about Online courses   join in Online courses
View Abhijit  Paul 's Profile

How do I find second highest value from a table?

Hi sir,

how to find the second highest value from a table....
Asked by Abhijit Paul | Nov 27, 2009 |  Reply now
Replies (1)
View teacher siliconindia 's Profile
Hi abhijit,

If you want to find the second highest value from a table, then simply order by the field you are interested in and take the second row, like this:

<?php

$query = mysql_query("SELECT number FROM table ORDER BY number DESC LIMIT 2");
$second_highest = mysql_result($query,1,0);
echo "the answer to your question is $second_highest";
?>
Nov 27, 2009