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::


$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'] ;


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

Edited by debasishgang7: n/a

6 Years
Discussion Span
Last Post by debasishgang7

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."

Edited by d5e5: Added something after the code snippet...

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.