Ajay
Ajay

Reputation: 21

Fetching top 5 records of maximum salary

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

Answers (2)

Weboide
Weboide

Reputation: 1110

You have to use LIMIT, like so:

SELECT * FROM mytable ORDER BY salary DESC LIMIT 5

Upvotes: 1

Mark Byers
Mark Byers

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

Related Questions