Solved

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

Posted on 2014-03-10
2
544 Views
Last Modified: 2014-03-10
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
Comment
Question by:lericson
2 Comments
 
LVL 27

Accepted Solution

by:
yodercm earned 500 total points
ID: 39919119
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
 

Author Closing Comment

by:lericson
ID: 39919169
Thanks!
0

Featured Post

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

A lot of articles have been written on splitting mysqldump and grabbing the required tables. A long while back, when Shlomi (http://code.openark.org/blog/mysql/on-restoring-a-single-table-from-mysqldump) had suggested a “sed” way, I actually shell …
I use MySQL for many of my development projects in a Windows environment. To manage my databases (and perform queries) for years I used a tool called MySQL administrator.  This tool has since been replaced by MySQL Workbench. So I decided to m…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question