- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
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
MySQL query to select the nth highest value in a column by skipping values
To get the nth highest value in a column, you can use LIMIT OFFSET. Here, OFFSET is used to skip the values. Let us first create a table −
mysql> create table DemoTable ( Value int ) ; Query OK, 0 rows affected (0.49 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values(100); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable values(140); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values(90); Query OK, 1 row affected (0.08 sec) mysql> insert into DemoTable values(80); Query OK, 1 row affected (0.09 sec) mysql> insert into DemoTable values(89); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable values(98); Query OK, 1 row affected (0.09 sec) mysql> insert into DemoTable values(58); Query OK, 1 row affected (0.10 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
This will produce the following output −
+-------+ | Value | +-------+ | 100 | | 140 | | 90 | | 80 | | 89 | | 98 | | 58 | +-------+ 7 rows in set (0.00 sec)
Following is the query to get the nth highest value in a column. Here, we are skipping 3 values using OFFSET 3. The same gives us the 4th highest value after using ORDER BY −
mysql> select Value from DemoTable order by Value limit 1 offset 3;
This will produce the following output −
+-------+ | Value | +-------+ | 90 | +-------+ 1 row in set (0.00 sec)
- Related Articles
- Select nth highest value in MySQL
- How to find nth highest value of a MySQL column?
- MySQL query to get first two highest column values from a table?
- MySQL query to select three highest values and sort alphabetically on the basis of corresponding column with name
- MySQL query to select rows where column value is only 0, group by another column?
- Select a specific value between two column values in MySQL?
- MySQL query to select column values ending with certain character/number?
- MongoDB query to find the highest numeric value of a column?
- Query to find Nth maximum value in MySQL
- How to add a column from a select query but the value from the new column will be the row count of the MySQL select query?
- MySQL query to select column where value = one or value = two, value = three, etc?
- Select minimum row value from a column with corresponding duplicate column values in MySQL
- MySQL query to display records ordered by DESC while skipping some?
- MySQL SELECT to add a new column to a query and give it a value?
- MySQL query to fetch the maximum corresponding value from duplicate column values

Advertisements