Find the ranking of an integer in mysql [duplicate]
Possible Duplicate: Mysql rank function I have the following countryTable country clicks ------- ------ 0 222 66 34 175 1000 45 650 How do I get the ranking of say country 45 which is 2 in this case? Ordered by country ASC : SELECT 1+COUNT(*) AS ranking FROM countryTable WHERE country < 45 ; Ordered by clicks DESC : SELECT 1+COUNT(*) AS ranking FROM countryTable AS t JOIN countryTable AS c ON c.clicks > t.clicks WHERE t.country = 45 ; You can get 2 rank as below it like below: Select * from tabeName order by clicks limit 1,1 For 3 rank: Select * from tabeName order by clicks limit 2,1 SELECT *