Hi all
i am trying to make a script which will select nth (1st,2nd blah blah..)highest record from Database.
Suppose i have a table with two columns "id" and "score".And for example i wanna select the "id" of member with the 5th highest score??
I am doing this with php
Here is my code::

<?php
include("inc/db.php");

$q = "SELECT id FROM members ORDER BY score desc LIMIT 5, 6";  //I am trying to 
select the id with 6th highest score

$result2 = mysql_query($q) or die (mysql_error());
while($row = mysql_fetch_array($result2))
	{
		echo  $row['id'] ;
	}

	mysql_close($con);
?>

The above code is not working...!!!What changes should i made in the Query??
Thank you.

SELECT id FROM members ORDER BY score desc LIMIT 6, 1

its not working ....

its not working ....

If you wanted to retrieve the highest score you would use offset of 0 (not 1). And so to retrieve the 6th highest score you need an offset of 5.

SELECT id FROM members ORDER BY score desc LIMIT 5, 1;

In English I think the above says something like, "skip the first five rows and then retrieve one row."

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.