santhosh
santhosh

Reputation: 161

how to select top 5 max values in mytable

Please help me with Query in Mysql.. i am Having table contains lot of rows .now i want retrive the 5 rows from that table.

my requirement is top maximum 5 values in that table "column name is amount" i want select from that table.outof N records i need top max 5 records from table

Thanking you,

Upvotes: 15

Views: 70590

Answers (2)

Teetrinker
Teetrinker

Reputation: 575

SELECT * FROM table ORDER BY amount DESC LIMIT 5;

Upvotes: 4

Alnitak
Alnitak

Reputation: 339816

Just order the rows by (descending) amount and take the top 5:

SELECT amount FROM mytable ORDER BY amount DESC LIMIT 5

Note that this will result in a full table scan unless you have an index on the amount column. This could affect performance if the number of rows in the table is very large (i.e. many thousands).

Upvotes: 36

Related Questions