PHP Questions Home
Categories
Arrays
Files
Forms
Creating PDFs
PHP Errors
Functions
Images
MySQL
Numbers
Others
Strings
Website

PHP Forums
Forums Index
MySQL Forum
PHP Forum
Flash/Actionscript
Javascript
Web design

More PHP
PHP Functions
Top Questions
Ask a Question
PHP Interview Questions
PHP Jobs
Ecommerce
IT Questions
Business Websites

Sponsors

sponsor ad
My Salary
PHP Developer Salary
Advertise Here

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!



ASK A QUESTION

More mysql PHP Questions

How do I order the results of my query?

Why will this statement not print a column with "lastname space firstname"? Print " .$info['businessname'] "; Print " .$info['firstname']. " " .$info['lastname'] "; I want to see 2 columns - a

I have a database with a table and in the table I have a row named php_code and I want to print the code of this row in my site as script. Example in row: and in my site: hello.

How do I access the current time with mysql?

How do I limit the number of rows returned?



Custom Search