Solved

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

Posted on 2014-03-10
2
555 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

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.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Insert data into database 2 45
configure dependency in POM for new database 3 34
Insert values are dynamic 11 51
AWS EC2 & RDS Instance 5 52
Foreword This article was written many years ago, in the days when PHP supported the MySQL extension (http://php.net/manual/en/function.mysql-connect.php).  Today (http://php.net/manual/en/migration70.removed-exts-sapis.php) you would not use MySQL…
Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
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 …
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

808 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