- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Select nth highest value in MySQL
To select the nth highest value in MySQL, following is the syntax −
select distinct(yourColumnName) from yourTableName order by yourColumnName DESC limit (NthValue-1),1;
Let us first create a table −
mysql> create table DemoTable1594 -> ( -> Marks int -> ); Query OK, 0 rows affected (0.49 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable1594 values(76); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable1594 values(95); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable1594 values(56); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable1594 values(96); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable1594 values(89); Query OK, 1 row affected (0.19 sec)
Display all records from the table using select statement −
mysql> select * from DemoTable1594;
This will produce the following output −
+-------+ | Marks | +-------+ | 76 | | 95 | | 56 | | 96 | | 89 | +-------+ 5 rows in set (0.00 sec)
Here is the query to select nth highest value −
mysql> select distinct(Marks) from DemoTable1594 order by Marks DESC limit 2,1;
This will produce the following output −
+-------+ | Marks | +-------+ | 89 | +-------+ 1 row in set (0.00 sec)
- Related Articles
- MySQL query to select the nth highest value in a column by skipping values
- How to find nth highest value of a MySQL column?
- Select highest salary in MySQL?
- Query to find Nth maximum value in MySQL
- How can I select the row with the highest ID in MySQL?
- MySQL order by from highest to lowest value?
- MySQL select count by value?
- How to select unique value in MySQL?
- Show column value twice in MySQL Select?
- How to get the fourth highest value using MySQL query?
- How to order by the highest value from two columns in MySQL?
- SELECT where row value contains string in MySQL?
- MySQL SELECT to sum a column value with previous value
- Perform multiplication in SELECT depending on column value in MySQL?
- Can we set a single value in MySQL SELECT IN()?

Advertisements