PHP Questions Home

Categories

Arrays
Files
Forms
Functions
Images
MySQL
Numbers
Others
Strings
Website


PHP Functions

PHP Functions


More PHP

Top Questions
Ask a Question

How do I find second highest value from a table?


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";
?>


And that's really all that there is to it... thanks for submitting your question!



More mysql PHP Questions

How do I find the longest value in my mysql table?
How do I include a conditional in my mysql query?
How do I find the ID of a new row added to a table?
How do I return a random row from the database?
How do I set a default value for ENUM fields in PHP?