• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 654
  • 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.
0
Lennart Ericson
Asked:
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.
0
 
Lennart EricsonAmateurAuthor Commented:
Thanks!
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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