Reputation: 21
I have 3 columns with id,usrnameand salary. I want to find maximum salary of 5 records. How will i write query in mysql ?
Upvotes: 2
Views: 11433
Reputation: 1110
You have to use LIMIT, like so:
SELECT * FROM mytable ORDER BY salary DESC LIMIT 5
Upvotes: 1
Reputation: 838336
In MySQL you can use ORDER BY to sort the rows in descending order and use LIMIT to return only the top 5 rows:
SELECT id, usrname, salary
FROM yourtable
ORDER BY salary DESC
LIMIT 5
Upvotes: 9