Page 1 of 1

Best way to get result position in mysql query?

Posted: Mon Jul 16, 2007 2:41 pm
by trobale
I have a table, users, that contains information about the user and also user points (I'm running a scoring system).

I'm wondering which way is the best to get a users ranking according to the points.

That is, I want to display the users ranking generated by the following query "SELECT * FROM users GROUP BY Points ORDER BY Points DESC"

Thanks.

Posted: Mon Jul 16, 2007 3:27 pm
by califdon
I don't understand your question. You have the correct query to do that. What else are you trying to do????

Posted: Mon Jul 16, 2007 3:35 pm
by trobale
Well, the information I want to display is similar to: User ranking: #22 (out of 1000 users) and I don't get the users ranking with that query.

I don't want rankings for all users, just for one user (specified by eg. his nick or user id)

Posted: Mon Jul 16, 2007 4:34 pm
by Jenk
Run a second (or sub) query to select a count of those with a score greater than the player's.

Code: Select all

SELECT COUNT(*) FROM players WHERE score > (SELECT score FROM players WHERE player_id = <the players id>)