posted 12 years ago
Sriinu, that is probably the worst way you can do this. Doing max on a huge table is not cheap. Doing it 3 times is even worse. Also, what if he wants the Nth salary, you will have N nested queries? Poor database!
Mathews approach seems to be the best one. Although I think we can do a little better. I believe MySQL allows you to offset the result set, so something like this will work
Select salary from user order by salary desc limit n-1, n
This will give you the nth largest salary