• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 726
  • Last Modified:

How to find second lowest, third lowest, ...nth lowest value in a MySQL column

Given this database table:

id         name             mark

1          John Deo         75
2          Max Ruin         85
3          Arnold             55
4          Krish Star        60

I'd like to find second lowest and third lowest
Searching the net I found a Query string andd tried it:

$SQL2 = "SELECT DISTINCT(name), id FROM table ORDER BY id DESC LIMIT 2, 1 ";
It failed.

Please, experts, could you lead me through this? Incidentally, at the end of the line its states "limit 2, 1". I wonder what ",1" is for. Should appreciate an explanation.
Lennart Ericson
Lennart Ericson
1 Solution
Cornelia YoderArtistCommented:
In your query, DESC will get the highest values.  To get lowest, use ASC (ascending).

The Limit 2,1 means to get two values, after skipping 1.
Lennart EricsonAmateurAuthor Commented:
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now