Student
Student

Reputation: 1863

How to get 2nd highest from table?

I have a table like this:

id  | name | class | marks 
 1  | abc  |  1    | 90
 2  | cdf  |  1    | 100  
 3  | xyz  |  1    | 70 

I want to get 2nd highest marks record. How can I get it with with one query. Simple and short?

Upvotes: 2

Views: 314

Answers (2)

Nanne
Nanne

Reputation: 64409

Use LIMIT and ORDER

SELECT * FROM table
ORDER BY marks DESC LIMIT 1,1

ORDER BY marks DESC means: descending ordering, so highest on top. LIMIT 1,1 means offset = 1 and only select 1 row.

Upvotes: 4

spanky
spanky

Reputation: 1499

SELECT * FROM `tableName` ORDER BY `marks` DESC LIMIT 1,1

Upvotes: 4

Related Questions